From patchwork Wed Jul 12 14:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13310442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 448D7C04E69 for ; Wed, 12 Jul 2023 14:25:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 690FC6B0075; Wed, 12 Jul 2023 10:25:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 640FF6B007D; Wed, 12 Jul 2023 10:25:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4450A6B0078; Wed, 12 Jul 2023 10:25:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 35D1B6B0074 for ; Wed, 12 Jul 2023 10:25:23 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D66451C8185 for ; Wed, 12 Jul 2023 14:25:22 +0000 (UTC) X-FDA: 81003182484.15.E29EDA6 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf22.hostedemail.com (Postfix) with ESMTP id ACCFFC0006 for ; Wed, 12 Jul 2023 14:25:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689171921; a=rsa-sha256; cv=none; b=SxE2gb88Eeo2c8CxpqxHl6rgxSL3s+W9ZsXh55ZBUzcXEXkMIkRyxDraaEAT6WdxPVJdAO /RPuPwpLg0EEAOBML45XM1hGSM/qgwRdZcrO53Sd4lb6sDC2oKx3EP7rSqYK4ry+BY2O/m 7aGoi4sb/f0lX6XzAKUaj8/0CM41Z3Q= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689171920; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i32xQsYNea2N3mRh+W5pA/MWZrgbJQEJwx4pUovWufk=; b=uhewK0RXyK+TJGvFpPnX9h2rVHzx7SpcW5ZLSA468QnfaGX2E9eMoABM70tmzPpBR7Krwf C7uaYVYlqWHJs6P4QZN2CfM7ubCRaoAi5VvnxjqlVfp/jdGmg+7op+ZLgIyMz+XXoeo+dj 3TQPACSaF9McEnB1I+86RNo6aLu/NUA= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R1KgS2xkDzMqYD; Wed, 12 Jul 2023 22:21:56 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 12 Jul 2023 22:25:12 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , Kefeng Wang Subject: [PATCH 2/5] mm: use vma_is_stack() and vma_is_heap() Date: Wed, 12 Jul 2023 22:38:28 +0800 Message-ID: <20230712143831.120701-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712143831.120701-1-wangkefeng.wang@huawei.com> References: <20230712143831.120701-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: ACCFFC0006 X-Stat-Signature: y68w55d86s4mhxwxhcqzjwed8xm33o6c X-HE-Tag: 1689171918-636894 X-HE-Meta: U2FsdGVkX19duWbGDoT3l+Tn9M1uv/GKQ8repeQs8JRrgmpDFB7TAYFEolLJn4uF11LAk3hWeXDd0tVTMME7A0X+lwlljXNnDnxbd9GSxJSU3fvJSAT6Kd/wpWLAfEM/fDVVsGmhqtbHQ1Vcj3pxGSf2O/Dk/QRiHaqgs9M4n6SYpZe85ZgHvhKhAMYLrSNZUeF7tvUrpSiMNj6We2okwoJn8Jq82sEPkWM5oud3Aoa9aYflXQA6WjMc5T1INiXGUhNiXsGzcHFk6HoyH560Um4IKWy6IEcHB/6jdEcF6UblFbp7kWeit+filisMPF1Wt/Bo0ulKkF36avKbSd5QJtnHLriHGCJmYEsT4swKk/UxmTTK/pNeKhuar91rSNn4HpOmp3KGWiseRn8YwZxwSguOZ+JyPLK15cGOjGRnsmoLy1ju7dUKNtEcqa4YrYxcgOBLJ5vcuhiGDD5LL61vSZufQEJmUO6T9vUqrMZDhvvDMugQNGXjYv/8dUPGeYmJZHUGsMzngrAyORTZW8/iux+rTEThBRnJI0msZRL6thwG3423cMUr7ltbR2YgdlTqDAPvoc9vhUYpvrd2tcDAEVJvwNwKoF97WU5VrfWVexFi/dISRyJWGvD3n+MyjsfePO1bzfXmqGygqNkPfvLUoYAaHzrU/IaflIB+qUBkypM5nIP7U50PHuZusLi1AX5CaaKvD+DiyF69+SH/y68KMIxbLcE9yVZdSztiCF63ztUzK1w6dicuh7/rJon2MArjvjJQ7i5/Nh+1KhJAovXUVR7COP12V/rS+w77nEzyudd2d57zrtv7o5exZAxFkPVy6CWoePECzb4xWHQPm0N4IYqDSnyGn4F70nbfX5TRG/LIDDcR0xGhIaa6yMdtYEyeAvAIejo/2N7Q8ZX4if6fDm5bz50vHR6xdVj5aUiWN8hHaQZNPzUEvjgL41GzCpAowuPuRXl3/zk1ggzMzwZ clq2OE68 Ws5PK6tZpNZboCt+8Ukc7phPPTknlVXpQLN9lPYIEN6Qa4VW9AhCSZohyihYgo7wNRK6ZahCv4x67BZtkShEp2GIZAfOow1CP1byFEp78gdFLtuh3MdOFBHiMkNtZOmgMN9RBGoUPgvZxjmCOswnPR13AnSho2B5V0BitwN1GoVWA4pjYyJFHMXasuf8sBH/vro94 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the helpers to simplify code. Signed-off-by: Kefeng Wang --- fs/proc/task_mmu.c | 24 ++++-------------------- fs/proc/task_nommu.c | 15 +-------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index cfab855fe7e9..05e9893552ce 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -236,21 +236,6 @@ static int do_maps_open(struct inode *inode, struct file *file, sizeof(struct proc_maps_private)); } -/* - * Indicate if the VMA is a stack for the given task; for - * /proc/PID/maps that is the stack of the main task. - */ -static int is_stack(struct vm_area_struct *vma) -{ - /* - * We make no effort to guess what a given thread considers to be - * its "stack". It's not even well-defined for programs written - * languages like Go. - */ - return vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack; -} - static void show_vma_header_prefix(struct seq_file *m, unsigned long start, unsigned long end, vm_flags_t flags, unsigned long long pgoff, @@ -327,13 +312,12 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma) goto done; } - if (vma->vm_start <= mm->brk && - vma->vm_end >= mm->start_brk) { + if (vma_is_heap(vma)) { name = "[heap]"; goto done; } - if (is_stack(vma)) { + if (vma_is_stack(vma)) { name = "[stack]"; goto done; } @@ -1974,9 +1958,9 @@ static int show_numa_map(struct seq_file *m, void *v) if (file) { seq_puts(m, " file="); seq_file_path(m, file, "\n\t= "); - } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { + } else if (vma_is_heap(vma)) { seq_puts(m, " heap"); - } else if (is_stack(vma)) { + } else if (vma_is_stack(vma)) { seq_puts(m, " stack"); } diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index 2c8b62265981..f42c84172b9e 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c @@ -121,19 +121,6 @@ unsigned long task_statm(struct mm_struct *mm, return size; } -static int is_stack(struct vm_area_struct *vma) -{ - struct mm_struct *mm = vma->vm_mm; - - /* - * We make no effort to guess what a given thread considers to be - * its "stack". It's not even well-defined for programs written - * languages like Go. - */ - return vma->vm_start <= mm->start_stack && - vma->vm_end >= mm->start_stack; -} - /* * display a single VMA to a sequenced file */ @@ -171,7 +158,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma) if (file) { seq_pad(m, ' '); seq_file_path(m, file, ""); - } else if (mm && is_stack(vma)) { + } else if (mm && vma_is_stack(vma)) { seq_pad(m, ' '); seq_puts(m, "[stack]"); }