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: 119229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1202569vqm; Wed, 12 Jul 2023 07:49:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlEK6aDr/zTwKn5fI5BUCO6cop6Ag0jSVavIi3QFB/r2+OWCFSqz9wqKQDgrPnHGzROZlhNc X-Received: by 2002:ac2:58f4:0:b0:4f8:596a:4bb7 with SMTP id v20-20020ac258f4000000b004f8596a4bb7mr13617578lfo.57.1689173352047; Wed, 12 Jul 2023 07:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689173352; cv=none; d=google.com; s=arc-20160816; b=dWHfiCs5QuNkO+KPs35e6IangEdSh7y5YEajVaZEN8OGq0M+T/IVjngBSHLqvUsjhN J1cQTEdOEOG4xXyAz6/2AIctC7V+9OVzl34agfk72oJ8yL5+pAE6Zhil95bOM4TsO2hO zgPAyONGq602GPq9b3ISc41imNzBQQJiqd+1N1aVTpJLBpOR3WLaWnWdFedZvT7eERGk TFzJVYJfPJ+jedVsLUT26vCOc7qle+1QDPZIiMY5DbuLfX6JUOlgp3SM/CeFlUKbBH2m pVqYK52Pyfnee/o1yRgVId/jj1Hyp+LRrXFnsu16od7LhoIS9ULXzkybR6T/e5qj3yU+ PZTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=i32xQsYNea2N3mRh+W5pA/MWZrgbJQEJwx4pUovWufk=; fh=FRon72YwFeIVU/LlfmPNxuVFiduvQKfa+Ydvnh8xLfc=; b=MlIY8mwPC1jwiBsvzaDw9OEQRqCl2P0+xw2o+yDg1fQaSMAOO8/nfBHUvxDeAmACCe EBRX7YQ4V2TmEDkZqk9Wm8EKaCT+7bpmibybUBZ3lrEScgHpl5vfBJ5ckyRuqqcQ9PAT K7HidIH9+KEzjJYDjpWypWUGJXRcUizKIppKmhhwlX3nXAUYPTjxPTXEpCNcGQzjJ1yv I9YTZ+j2n1ioiPCE8EqIwdHvTnqtjm61/dg1gWV6cUcLJLHNaX6LliySeLeM/zB2YSGJ gLeSYQw4weMGFR1CwJFaOQ7cN4j9F9JEJrSAZqQknwWMNgaJRotl/ebxEYMA4Kfu5ETW SlxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w10-20020aa7cb4a000000b0051e0ea53eafsi4734443edt.558.2023.07.12.07.48.47; Wed, 12 Jul 2023 07:49:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232356AbjGLOZV (ORCPT + 99 others); Wed, 12 Jul 2023 10:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231827AbjGLOZU (ORCPT ); Wed, 12 Jul 2023 10:25:20 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72D7419A3; Wed, 12 Jul 2023 07:25:15 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771226636993497920 X-GMAIL-MSGID: 1771226636993497920 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]"); }