Skip to content

Commit

Permalink
Add vm_fadvise
Browse files Browse the repository at this point in the history
  • Loading branch information
c2main committed Dec 4, 2023
1 parent 36c8187 commit 7ee42b1
Show file tree
Hide file tree
Showing 5 changed files with 473 additions and 0 deletions.
70 changes: 70 additions & 0 deletions expected/pgfincore.out
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,73 @@ select (pgfincore('test')).pages_mem, (vm_cachestat('test', 'main', NULL, NULL))
0 | 0
(1 row)

--
-- tests vm_fadvise
--
-- Test bad parameters
select vm_fadvise(NULL, NULL, -1, -1, 'badflag');
ERROR: relation cannot be NULL
HINT: check parameters
select vm_fadvise('test', NULL, -1, -1, 'badflag');
ERROR: relation fork cannot be NULL
HINT: check parameters
select vm_fadvise('test', 'vm', -1, -1, 'badflag');
ERROR: starting block number cannot be negative
HINT: check parameters
select vm_fadvise('test', 'main', -1, -1, 'badflag');
ERROR: starting block number cannot be negative
HINT: check parameters
select vm_fadvise('test', 'main', NULL, -1, 'badflag');
ERROR: number of blocks cannot be negative
HINT: check parameters
select vm_fadvise('test', 'main', 10, NULL, 'badflag');
ERROR: Invalid advice string: badflag
HINT: check parameters
select vm_fadvise('test', 'main', 0, 10, 'badflag');
ERROR: Invalid advice string: badflag
HINT: check parameters
select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_NOREUSE');
ERROR: POSIX_FADV_NOREUSE is no-op
-- Working cases
select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_NORMAL');
vm_fadvise
------------

(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_SEQUENTIAL');
vm_fadvise
------------

(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_RANDOM');
vm_fadvise
------------

(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_DONTNEED');
vm_fadvise
------------

(1 row)

select (pgfincore('test')).pages_mem;
pages_mem
-----------
0
(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_WILLNEED');
vm_fadvise
------------

(1 row)

select (pgfincore('test')).pages_mem;
pages_mem
-----------
4
(1 row)

70 changes: 70 additions & 0 deletions expected/pgfincore_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,73 @@ select from pgfadvise_loader('test', 0, true, true, B'0000');
select (pgfincore('test')).pages_mem, (vm_cachestat('test', 'main', NULL, NULL)).nr_cache;
ERROR: sys_cachestat is not available: Function not implemented
HINT: linux 6.5 minimum is required!
--
-- tests vm_fadvise
--
-- Test bad parameters
select vm_fadvise(NULL, NULL, -1, -1, 'badflag');
ERROR: relation cannot be NULL
HINT: check parameters
select vm_fadvise('test', NULL, -1, -1, 'badflag');
ERROR: relation fork cannot be NULL
HINT: check parameters
select vm_fadvise('test', 'vm', -1, -1, 'badflag');
ERROR: starting block number cannot be negative
HINT: check parameters
select vm_fadvise('test', 'main', -1, -1, 'badflag');
ERROR: starting block number cannot be negative
HINT: check parameters
select vm_fadvise('test', 'main', NULL, -1, 'badflag');
ERROR: number of blocks cannot be negative
HINT: check parameters
select vm_fadvise('test', 'main', 10, NULL, 'badflag');
ERROR: Invalid advice string: badflag
HINT: check parameters
select vm_fadvise('test', 'main', 0, 10, 'badflag');
ERROR: Invalid advice string: badflag
HINT: check parameters
select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_NOREUSE');
ERROR: POSIX_FADV_NOREUSE is no-op
-- Working cases
select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_NORMAL');
vm_fadvise
------------

(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_SEQUENTIAL');
vm_fadvise
------------

(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_RANDOM');
vm_fadvise
------------

(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_DONTNEED');
vm_fadvise
------------

(1 row)

select (pgfincore('test')).pages_mem;
pages_mem
-----------
0
(1 row)

select vm_fadvise('test', 'main', 0, 2, 'POSIX_FADV_WILLNEED');
vm_fadvise
------------

(1 row)

select (pgfincore('test')).pages_mem;
pages_mem
-----------
4
(1 row)

12 changes: 12 additions & 0 deletions pgfincore--1.3.1--2.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ AS $vm_cachestat$
SELECT * FROM vm_cachestat($1,'main',NULL,NULL)
$vm_cachestat$
LANGUAGE SQL;

CREATE OR REPLACE FUNCTION
vm_fadvise(
relation regclass
, fork_name text
, block_num bigint
, nblocks bigint
, advice text
)
RETURNS VOID
AS '$libdir/pgfincore'
LANGUAGE C;
Loading

0 comments on commit 7ee42b1

Please sign in to comment.