Date: Sat, 3 Jul 2021 11:34:50 +0300 From: Vitaliy Gusev <gusev.vitaliy@gmail.com> To: gljennjohn@gmail.com Cc: freebsd-hackers@freebsd.org, "kib@freebsd.org" <kib@FreeBSD.org> Subject: Re: madvise(MADV_FREE) doesn't work in some cases? Message-ID: <D542E8C1-4E97-48E8-8748-BBA19B2216EC@gmail.com> In-Reply-To: <20210703065420.6dbafb5f@ernst.home> References: <D5749BDF-36B5-4AE9-A75F-2A702DF71F8C@gmail.com> <20210703065420.6dbafb5f@ernst.home>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_E13708A3-36BC-422B-A795-631242F67439
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
> On 3 Jul 2021, at 09:54, Gary Jennejohn <gljennjohn@gmail.com> wrote:
>=20
> The FreeBSD mail server apparently removed the attachment.
>=20
> So either provide it in-line or put it on some pubic file server and
> add a link to it.
>=20
> --=20
> Gary Jennejohn
#include <sys/mman.h>
#include <err.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
size_t len =3D (size_t)(argc > 1 ? atoi(argv[1]) : 1024) * 1024 =
* 1024;
uint8_t *ptr, *end, *p;
unsigned pagesz =3D 1<<12;
int pid;
ptr =3D mmap(NULL, len, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | =
MAP_PRIVATE, -1, 0);
if (ptr =3D=3D MAP_FAILED)
err(1, "cannot mmap");
end =3D ptr + len;
printf("mmap %p pid %d\n", ptr, getpid());
printf("end %p len %#lx\n", end, len);
fflush(stdout);
pid =3D fork();
if (pid < 0)
err(1, "cannot fork");
printf("pid %d\n", getpid());
sleep(pid =3D=3D 0 ? 1 : 14);
printf("%d: touch\n", getpid());
p =3D ptr;
while (p < end) {
*p =3D 1;
p +=3D pagesz;
}
printf("%d: sleep before madvise\n", getpid());
sleep(pid =3D=3D 0 ? 1 : 4);
printf("%d, madvise\n", getpid());
p =3D ptr;
while (p < end) {
int error;
error =3D madvise(p, pagesz, MADV_FREE);
if (error) {
err(1, "cannot madvise");
}
p +=3D pagesz;
}
printf("%d: Press enter to exit\n", getpid());
getchar();
}
=E2=80=94=E2=80=94
Vitaliy Gusev=
--Apple-Mail=_E13708A3-36BC-422B-A795-631242F67439--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?D542E8C1-4E97-48E8-8748-BBA19B2216EC>
