Skip to content

Commit f261c4e

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc patches from Andrew Morton: - a little bit more MM - a few fixups [ The "little bit more MM" is actually just one of the three patches Andrew sent for mm/filemap.c, I'm still mulling over two more of them from Josef Bacik - Linus ] * emailed patches from Andrew Morton <akpm@linux-foundation.org>: include/linux/swap.h: use offsetof() instead of custom __swapoffset macro tools/testing/selftests/proc/proc-pid-vm.c: test with vsyscall in mind zram: default to lzo-rle instead of lzo filemap: pass vm_fault to the mmap ra helpers
2 parents 3b319ee + a4046c0 commit f261c4e

File tree

4 files changed

+63
-20
lines changed

4 files changed

+63
-20
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static DEFINE_IDR(zram_index_idr);
4141
static DEFINE_MUTEX(zram_index_mutex);
4242

4343
static int zram_major;
44-
static const char *default_compressor = "lzo";
44+
static const char *default_compressor = "lzo-rle";
4545

4646
/* Module params (documentation at end) */
4747
static unsigned int num_devices = 1;

include/linux/swap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ struct swap_extent {
157157
/*
158158
* Max bad pages in the new format..
159159
*/
160-
#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
161160
#define MAX_SWAP_BADPAGES \
162-
((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
161+
((offsetof(union swap_header, magic.magic) - \
162+
offsetof(union swap_header, info.badpages)) / sizeof(int))
163163

164164
enum {
165165
SWP_USED = (1 << 0), /* is slot in swap_info[] used? */

mm/filemap.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,20 +2420,20 @@ static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask)
24202420
* Synchronous readahead happens when we don't even find
24212421
* a page in the page cache at all.
24222422
*/
2423-
static void do_sync_mmap_readahead(struct vm_area_struct *vma,
2424-
struct file_ra_state *ra,
2425-
struct file *file,
2426-
pgoff_t offset)
2423+
static void do_sync_mmap_readahead(struct vm_fault *vmf)
24272424
{
2425+
struct file *file = vmf->vma->vm_file;
2426+
struct file_ra_state *ra = &file->f_ra;
24282427
struct address_space *mapping = file->f_mapping;
2428+
pgoff_t offset = vmf->pgoff;
24292429

24302430
/* If we don't want any read-ahead, don't bother */
2431-
if (vma->vm_flags & VM_RAND_READ)
2431+
if (vmf->vma->vm_flags & VM_RAND_READ)
24322432
return;
24332433
if (!ra->ra_pages)
24342434
return;
24352435

2436-
if (vma->vm_flags & VM_SEQ_READ) {
2436+
if (vmf->vma->vm_flags & VM_SEQ_READ) {
24372437
page_cache_sync_readahead(mapping, ra, file, offset,
24382438
ra->ra_pages);
24392439
return;
@@ -2463,16 +2463,16 @@ static void do_sync_mmap_readahead(struct vm_area_struct *vma,
24632463
* Asynchronous readahead happens when we find the page and PG_readahead,
24642464
* so we want to possibly extend the readahead further..
24652465
*/
2466-
static void do_async_mmap_readahead(struct vm_area_struct *vma,
2467-
struct file_ra_state *ra,
2468-
struct file *file,
2469-
struct page *page,
2470-
pgoff_t offset)
2466+
static void do_async_mmap_readahead(struct vm_fault *vmf,
2467+
struct page *page)
24712468
{
2469+
struct file *file = vmf->vma->vm_file;
2470+
struct file_ra_state *ra = &file->f_ra;
24722471
struct address_space *mapping = file->f_mapping;
2472+
pgoff_t offset = vmf->pgoff;
24732473

24742474
/* If we don't want any read-ahead, don't bother */
2475-
if (vma->vm_flags & VM_RAND_READ)
2475+
if (vmf->vma->vm_flags & VM_RAND_READ)
24762476
return;
24772477
if (ra->mmap_miss > 0)
24782478
ra->mmap_miss--;
@@ -2531,10 +2531,10 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
25312531
* We found the page, so try async readahead before
25322532
* waiting for the lock.
25332533
*/
2534-
do_async_mmap_readahead(vmf->vma, ra, file, page, offset);
2534+
do_async_mmap_readahead(vmf, page);
25352535
} else if (!page) {
25362536
/* No page in the page cache at all */
2537-
do_sync_mmap_readahead(vmf->vma, ra, file, offset);
2537+
do_sync_mmap_readahead(vmf);
25382538
count_vm_event(PGMAJFAULT);
25392539
count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT);
25402540
ret = VM_FAULT_MAJOR;

tools/testing/selftests/proc/proc-pid-vm.c

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@
2929
#include <errno.h>
3030
#include <sched.h>
3131
#include <signal.h>
32+
#include <stdbool.h>
3233
#include <stdint.h>
3334
#include <stdio.h>
3435
#include <string.h>
3536
#include <stdlib.h>
3637
#include <sys/mount.h>
3738
#include <sys/types.h>
3839
#include <sys/stat.h>
40+
#include <sys/wait.h>
3941
#include <fcntl.h>
4042
#include <unistd.h>
4143
#include <sys/syscall.h>
4244
#include <sys/uio.h>
4345
#include <linux/kdev_t.h>
46+
#include <sys/time.h>
47+
#include <sys/resource.h>
4448

4549
static inline long sys_execveat(int dirfd, const char *pathname, char **argv, char **envp, int flags)
4650
{
@@ -205,12 +209,44 @@ static int make_exe(const uint8_t *payload, size_t len)
205209
}
206210
#endif
207211

212+
static bool g_vsyscall = false;
213+
214+
static const char str_vsyscall[] =
215+
"ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n";
216+
208217
#ifdef __x86_64__
218+
/*
219+
* vsyscall page can't be unmapped, probe it with memory load.
220+
*/
221+
static void vsyscall(void)
222+
{
223+
pid_t pid;
224+
int wstatus;
225+
226+
pid = fork();
227+
if (pid < 0) {
228+
fprintf(stderr, "fork, errno %d\n", errno);
229+
exit(1);
230+
}
231+
if (pid == 0) {
232+
struct rlimit rlim = {0, 0};
233+
(void)setrlimit(RLIMIT_CORE, &rlim);
234+
*(volatile int *)0xffffffffff600000UL;
235+
exit(0);
236+
}
237+
wait(&wstatus);
238+
if (WIFEXITED(wstatus)) {
239+
g_vsyscall = true;
240+
}
241+
}
242+
209243
int main(void)
210244
{
211245
int pipefd[2];
212246
int exec_fd;
213247

248+
vsyscall();
249+
214250
atexit(ate);
215251

216252
make_private_tmp();
@@ -261,9 +297,9 @@ int main(void)
261297
snprintf(buf0 + MAPS_OFFSET, sizeof(buf0) - MAPS_OFFSET,
262298
"/tmp/#%llu (deleted)\n", (unsigned long long)st.st_ino);
263299

264-
265300
/* Test /proc/$PID/maps */
266301
{
302+
const size_t len = strlen(buf0) + (g_vsyscall ? strlen(str_vsyscall) : 0);
267303
char buf[256];
268304
ssize_t rv;
269305
int fd;
@@ -274,13 +310,16 @@ int main(void)
274310
return 1;
275311
}
276312
rv = read(fd, buf, sizeof(buf));
277-
assert(rv == strlen(buf0));
313+
assert(rv == len);
278314
assert(memcmp(buf, buf0, strlen(buf0)) == 0);
315+
if (g_vsyscall) {
316+
assert(memcmp(buf + strlen(buf0), str_vsyscall, strlen(str_vsyscall)) == 0);
317+
}
279318
}
280319

281320
/* Test /proc/$PID/smaps */
282321
{
283-
char buf[1024];
322+
char buf[4096];
284323
ssize_t rv;
285324
int fd;
286325

@@ -319,6 +358,10 @@ int main(void)
319358
for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) {
320359
assert(memmem(buf, rv, S[i], strlen(S[i])));
321360
}
361+
362+
if (g_vsyscall) {
363+
assert(memmem(buf, rv, str_vsyscall, strlen(str_vsyscall)));
364+
}
322365
}
323366

324367
/* Test /proc/$PID/smaps_rollup */

0 commit comments

Comments
 (0)