LCOV - code coverage report
Current view: top level - src/port - pg_numa.c (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 2 6 33.3 %
Date: 2025-04-24 12:15:10 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * pg_numa.c
       4             :  *      Basic NUMA portability routines
       5             :  *
       6             :  *
       7             :  * Copyright (c) 2025, PostgreSQL Global Development Group
       8             :  *
       9             :  *
      10             :  * IDENTIFICATION
      11             :  *    src/port/pg_numa.c
      12             :  *
      13             :  *-------------------------------------------------------------------------
      14             :  */
      15             : 
      16             : #include "c.h"
      17             : #include <unistd.h>
      18             : 
      19             : #include "port/pg_numa.h"
      20             : 
      21             : /*
      22             :  * At this point we provide support only for Linux thanks to libnuma, but in
      23             :  * future support for other platforms e.g. Win32 or FreeBSD might be possible
      24             :  * too. For Win32 NUMA APIs see
      25             :  * https://learn.microsoft.com/en-us/windows/win32/procthread/numa-support
      26             :  */
      27             : #ifdef USE_LIBNUMA
      28             : 
      29             : #include <numa.h>
      30             : #include <numaif.h>
      31             : 
      32             : /* libnuma requires initialization as per numa(3) on Linux */
      33             : int
      34             : pg_numa_init(void)
      35             : {
      36             :     int         r = numa_available();
      37             : 
      38             :     return r;
      39             : }
      40             : 
      41             : /*
      42             :  * We use move_pages(2) syscall here - instead of get_mempolicy(2) - as the
      43             :  * first one allows us to batch and query about many memory pages in one single
      44             :  * giant system call that is way faster.
      45             :  */
      46             : int
      47             : pg_numa_query_pages(int pid, unsigned long count, void **pages, int *status)
      48             : {
      49             :     return numa_move_pages(pid, count, pages, NULL, status, 0);
      50             : }
      51             : 
      52             : int
      53             : pg_numa_get_max_node(void)
      54             : {
      55             :     return numa_max_node();
      56             : }
      57             : 
      58             : #else
      59             : 
      60             : /* Empty wrappers */
      61             : int
      62          14 : pg_numa_init(void)
      63             : {
      64             :     /* We state that NUMA is not available */
      65          14 :     return -1;
      66             : }
      67             : 
      68             : int
      69           0 : pg_numa_query_pages(int pid, unsigned long count, void **pages, int *status)
      70             : {
      71           0 :     return 0;
      72             : }
      73             : 
      74             : int
      75           0 : pg_numa_get_max_node(void)
      76             : {
      77           0 :     return 0;
      78             : }
      79             : 
      80             : #endif

Generated by: LCOV version 1.14