Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp507462ima; Fri, 26 Oct 2018 01:51:46 -0700 (PDT) X-Google-Smtp-Source: AJdET5e9b6YNmh/Nn0X8Wmbg9Ptu4E8SQ6SzCB6zH54RwkqefQsSUkrcIBf6pe4mSek883PUubM7 X-Received: by 2002:a17:902:f24:: with SMTP id 33-v6mr2638502ply.218.1540543906864; Fri, 26 Oct 2018 01:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540543906; cv=none; d=google.com; s=arc-20160816; b=1JjVmfraV97bI8TcVFOhaWpHC4XnEAgGw/GvepMFhf3JGmIOrVATb25/b1K3esmJUr piLnCbk38V2PKjix5MY7SfK7bY7rD0OLds4byB4H7yQXRepqrOEwvjTFIe5JtX5AyxZj QEo6HGcXRR51tpgm/Vn840Ccw3RnpRHJhQWbzgJVlpmMvMzHLCcNNSBBvVO9qwnRB0sh jBmuLfWQ/YKwg8N5K4j4HdTeaqNTMr2oQPe27ygPdZOIpO3kJ0O++y6z5ItCAeBGM0Xu Wp6ezmMieA1eIgtvUKGDu37qbypaO+XNQFqMoGKU8EYStt9tMGLqVCtXh0V0dxm5n1Ma /i/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=FW7YwvbLhBHQc5+u2QSt2w05RD1XeNOF3IzJaydfsn4=; b=fNrSxxnEH60E/dxtUxXly+2RUuUTVnxYPAdXo196sJhF7+EVmdv3CmLOHZc84Td7Cl zR+179snVj+2X3kv7vaGuoIoRttCxjM1n5o/6NcOfP0TJHG9t0Knui40FHbrh374nHib N0cB7BQW+oiVKDkmpbTd+3OkU34QhCO7CnkP0ebi+vtPKdj38DfCNkJxh0E1U6O5j8JI JDbsc87Jws1B3YVuKv1stgknBr+N9WDpK3NvAFeQUj9AhON9Ixj7MSDFVMe+ht4LYwfg 73vXSYjJVFQ8E/K92p5CgeLsqJHDWOAdO9F/fRfqHFcxIbVy04aUGwakGXE3FE7V15nK mOLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15-v6si10560740pgh.33.2018.10.26.01.51.31; Fri, 26 Oct 2018 01:51:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727308AbeJZR06 (ORCPT + 99 others); Fri, 26 Oct 2018 13:26:58 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:29302 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726348AbeJZR06 (ORCPT ); Fri, 26 Oct 2018 13:26:58 -0400 X-UUID: 75866f457ae5466484c6153097eda7aa-20181026 X-UUID: 75866f457ae5466484c6153097eda7aa-20181026 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 210528792; Fri, 26 Oct 2018 16:50:35 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 26 Oct 2018 16:50:34 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 26 Oct 2018 16:50:34 +0800 Message-ID: <1540543834.21297.14.camel@mtkswgap22> Subject: Re: [PATCH] mm/page_owner: use vmalloc instead of kmalloc From: Miles Chen To: Matthew Wilcox CC: Matthias Brugger , , , , , Date: Fri, 26 Oct 2018 16:50:34 +0800 In-Reply-To: <20181025192701.GK25444@bombadil.infradead.org> References: <1540492481-4144-1-git-send-email-miles.chen@mediatek.com> <20181025192701.GK25444@bombadil.infradead.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-10-25 at 12:27 -0700, Matthew Wilcox wrote: > On Fri, Oct 26, 2018 at 02:34:41AM +0800, miles.chen@mediatek.com wrote: > > The kbuf used by page owner is allocated by kmalloc(), > > which means it can use only normal memory and there might > > be a "out of memory" issue when we're out of normal memory. > > > > Use vmalloc() so we can also allocate kbuf from highmem > > on 32bit kernel. > > ... hang on, there's a bigger problem here. > > static const struct file_operations proc_page_owner_operations = { > .read = read_page_owner, > }; > > read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos) > { > ... > return print_page_owner(buf, count, pfn, page, > page_owner, handle); > } > > static ssize_t > print_page_owner(char __user *buf, size_t count, unsigned long pfn, > struct page *page, struct page_owner *page_owner, > depot_stack_handle_t handle) > {mount -t debugfs none /sys/kernel/debug/ > ... > kbuf = kmalloc(count, GFP_KERNEL); > > So I can force the kernel to make an arbitrary size allocation, triggering > OOMs and forcing swapping if I can get a file handle to this file. > The only saving grace is that (a) this is a debugfs file and (b) it's > root-only (mode 0400). Nevertheless, I feel some clamping is called > for here. Do we really need to output more than 4kB worth of text here? > I did a test on my device, the allocation count is 4096 and around 6xx bytes are used each print_page_owner() is called. It looks like that clamping the reading count to PAGE_SIZE is ok. The following output from print_page_owner() is 660 bytes long, I think PAGE_SIZE should be enough to print the information we need. Page allocated via order 0, mask 0x6200ca(GFP_HIGHUSER_MOVABLE) PFN 262199 type Movable Block 512 type Movable Flags 0x4003c(referenced| uptodate|dirty|lru|swapbacked) get_page_from_freelist+0x1580/0x1650 __alloc_pages_nodemask+0xcc/0xfa4 shmem_alloc_page+0xa4/0xc8 shmem_alloc_and_acct_page+0x138/0x2b8 shmem_getpage_gfp.isra.54+0x164/0xfc8 shmem_write_begin+0x84/0xcc generic_perform_write+0xe8/0x210 __generic_file_write_iter+0x1d4/0x230 generic_file_write_iter+0x184/0x2e8 new_sync_write+0x144/0x1c4 vfs_write+0x194/0x278 ksys_write+0x64/0xd4 xwrite+0x34/0x84 do_copy+0xf4/0x168 flush_buffer+0x68/0xec __gunzip+0x370/0x448