b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From: Andy Whitcroft <apw@canonical.com> |
| 2 | Subject: [PATCH] MMAP_EXTEND mode requires we extend in full system page increments |
| 3 | Date: Wed, 12 Mar 2014 11:58:31 +0100 |
| 4 | |
| 5 | When extending a mmap file we must ensure we extend by full system pages, |
| 6 | otherwise there is a risk (when the filesystem page size is smaller than |
| 7 | the system page size) that we will not allocate disk extents to store |
| 8 | the memory and it will be lost resulting in data loss. |
| 9 | |
| 10 | Signed-off-by: Andy Whitcroft <apw@canonical.com> |
| 11 | Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> |
| 12 | |
| 13 | --- |
| 14 | env_file.c | 9 +++++++++ |
| 15 | 1 file changed, 9 insertions(+) |
| 16 | |
| 17 | --- a/src/env/env_file.c |
| 18 | +++ b/src/env/env_file.c |
| 19 | @@ -28,6 +28,15 @@ __db_file_extend(env, fhp, size) |
| 20 | int ret; |
| 21 | char buf; |
| 22 | |
| 23 | +#ifdef HAVE_MMAP_EXTEND |
| 24 | + /* |
| 25 | + * We have to ensure we extend a mmap'd segment a full memory page at |
| 26 | + * a time or risk the end of the page not having any filesystem blocks |
| 27 | + * associated resulting in the data loss. |
| 28 | + */ |
| 29 | + size = DB_ALIGN(size, getpagesize()) - 1; |
| 30 | +#endif |
| 31 | + |
| 32 | buf = '\0'; |
| 33 | /* |
| 34 | * Extend the file by writing the last page. If the region is >4Gb, |