Subject: kern/7511: madvise(2) is not implemented
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mrg@eterna.com.au>
List: netbsd-bugs
Date: 05/02/1999 18:32:47
>Number:         7511
>Category:       kern
>Synopsis:       madvise(2) is not implemented
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May  2 18:05:00 1999
>Last-Modified:
>Originator:     matthew green
>Organization:
people's front against (bozotic) www (softwar foundation)
>Release:        <NetBSD-current source date>any
>Environment:
	
System: NetBSD splode.eterna.com.au 1.3I NetBSD 1.3I (_splode_) #388: Wed Feb 10 13:21:23 EST 1999 mrg@splode.eterna.com.au:/orb/v/src/sys/arch/sparc/compile/_splode_ sparc

>Description:

NetBSD has never supported the madvise() system call.  UVM has added the
internal VM hooks to implement advice but once it is set, you can't change
it's behaviour.  this is because the madvise system call reads:

	int
	sys_madvise(p, v, retval)
		struct proc *p;
		void *v;
		register_t *retval;
	{
	#if 0
		struct sys_madvise_args /* {
				     syscallarg(caddr_t) addr;
				     syscallarg(size_t) len;
				     syscallarg(int) behav;
				     } */ *uap = v;
	#endif

		return (ENOSYS);
	}



>How-To-Repeat:

write an application that uses MADV_SEQUENTIAL, expecting the VM system
to deactivate pages after you have looked at them and notice that this
does not appear to happen.  scratch head and read the source (mmm, source)
and realise that while the code does advice you can't change it.

>Fix:
	
write sys_madvise() function to do the following:

	(a) for MADV_{NORMAL,RANDOM,SEQUENTIAL} update the advice of the
	    affected maps so that future faults have the expected behaviour.
	(b) for MADV_WILLNEED -- what to do here?  i'm not sure of the best
	    way to handle this request.
	(c) for MADV_DONTNEED deactivate the pages immediately (but do not
	    free them).
	(d) MADV_SAPCEAVAIL -- what to do here also?


i plan on addressing this myself at sometime in the near future, but
wanted to get it logged into the PR database, and also request comments
on (b) and (d) above from others.
>Audit-Trail:
>Unformatted: