From patchwork Sun Sep 26 16:12:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12518949 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F14CAC433EF for ; Sun, 26 Sep 2021 23:44:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A750B61154 for ; Sun, 26 Sep 2021 23:44:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A750B61154 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5895D6B0080; Sun, 26 Sep 2021 19:44:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 538816B0081; Sun, 26 Sep 2021 19:44:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38A59900002; Sun, 26 Sep 2021 19:44:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 2136C6B0080 for ; Sun, 26 Sep 2021 19:44:05 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B9FFC181B04B5 for ; Sun, 26 Sep 2021 23:44:04 +0000 (UTC) X-FDA: 78631355208.37.63D13EB Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf13.hostedemail.com (Postfix) with ESMTP id 82245103200C for ; Sun, 26 Sep 2021 23:44:04 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id on12-20020a17090b1d0c00b001997c60aa29so10371217pjb.1 for ; Sun, 26 Sep 2021 16:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nT513pHzGiMpZgaNWaHuaQRUoarxEdG+vAAtn4ZSI3I=; b=VGC5hFjSViPa8UHidrJ+zGmm4I8RPo6B7NhutVuOVsVcLYUwKbN/PoKdD3xiLZf+aJ 2IOUexZRK1VfbIoDyIRMQgknoPmXlBigfdQqKZlIDe4zqGJhVLh4ZnGIge5Fcqt3qWfE G+qfmVSSKT9ury1J76cbONnaDrXRyELY35rDHMDgMpo1/5ImYxUyf6WtF2Egyp824oiG 5HgNQH3Mi7HDBi4WcV5y8UwFDosNb7948/+VIxJAg9Vt9xZore2YBCJe/tyC2qxM/znX VAKeIIgY2ri6qy2XDBtI8D9wIPbEtQMGtia55vazq3FxpZ6D5erBdureiFmy6KdsgN5y sOog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nT513pHzGiMpZgaNWaHuaQRUoarxEdG+vAAtn4ZSI3I=; b=CeKI/A3uGvita7K6jIV0+e5fYW68U09g2+GsKsPR0z9jhDCzek6uvvSJuZOkiaQF87 I5qFxFu4Kq/vSl6biqdglwzZH2i8rZgThtdSXdLwOVJQRdkGJgLNCyP/aWc9qvKItsAD TJqmbOa2jR2oY8oiEsmfOBiDrsxDdqwVFyHq3N2Qan0LZYXNICYghWjN4z1yv3qCjDqx roQRPE99tzGb8CLJ6kt+V/qfJLnChD1nsyrr2H0Wh+qw6vYONuoh22Xk5uRDb7BiQpNH pu8EIgI3Gqs53m+1TWe+aMOTstalAxsVRwm0v6bJua7bvQPemQ/DT0Dex6hSfsAFHqWd RyDw== X-Gm-Message-State: AOAM531WjI9cyqhm8MI/kk0xoUiYOZcKWSW+88/lmPG4VPTb5jTAP1Cm vlQKZ6Ny0y4niBVSXZ1RnfY= X-Google-Smtp-Source: ABdhPJzAfS8fiN3mGvz5Edu6ZGWMLuREZwgR5MIc7fZhEaI1QNeFZ6PR8DwlKpq2jWtYM1A1vIEMBA== X-Received: by 2002:a17:90b:33c8:: with SMTP id lk8mr16244064pjb.241.1632699843558; Sun, 26 Sep 2021 16:44:03 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id n22sm16783686pgc.55.2021.09.26.16.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 16:44:03 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peter Xu , Nadav Amit , Andrea Arcangeli , Minchan Kim , Colin Cross , Suren Baghdasarya , Mike Rapoport Subject: [RFC PATCH 7/8] mm/madvise: deduplicate code in madvise_dontneed_free() Date: Sun, 26 Sep 2021 09:12:58 -0700 Message-Id: <20210926161259.238054-8-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210926161259.238054-1-namit@vmware.com> References: <20210926161259.238054-1-namit@vmware.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 82245103200C X-Stat-Signature: 5bqkfrrfwfe9hkizeazcyrqceticuf6z Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VGC5hFjS; spf=none (imf13.hostedemail.com: domain of mail-pj1-f52.google.com has no SPF policy when checking 209.85.216.52) smtp.helo=mail-pj1-f52.google.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-HE-Tag: 1632699844-331355 X-Bogosity: Ham, tests=bogofilter, spamicity=0.002827, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Nadav Amit Following the previous patches, madvise_dontneed_single_vma() and madvise_free_single_vma() have redundant code. Consolidate it together into madvise_dontneed_free(). Cc: Andrea Arcangeli Cc: Andrew Morton Cc: Minchan Kim Cc: Colin Cross Cc: Suren Baghdasarya Cc: Mike Rapoport Signed-off-by: Nadav Amit --- mm/madvise.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index e679cfa94655..9528c38fb6a4 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -786,25 +786,14 @@ static int madvise_free_single_vma(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start_addr, unsigned long end_addr) { - struct mm_struct *mm = vma->vm_mm; - struct mmu_notifier_range range; - /* MADV_FREE works for only anon vma at the moment */ if (!vma_is_anonymous(vma)) return -EINVAL; - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, - start_addr, end_addr); - - lru_add_drain(); - update_hiwater_rss(mm); - - mmu_notifier_invalidate_range_start(&range); tlb_start_vma(&tlb, vma); - walk_page_range(vma->vm_mm, range.start, range.end, + walk_page_range(vma->vm_mm, start_addr, end_addr, &madvise_free_walk_ops, tlb); tlb_end_vma(tlb, vma); - mmu_notifier_invalidate_range_end(&range); return 0; } @@ -832,18 +821,7 @@ static long madvise_dontneed_single_vma(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start, unsigned long end) { - struct mm_struct *mm = vma->vm_mm; - struct mmu_notifier_range range; - - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, start, - end); - - lru_add_drain(); - update_hiwater_rss(mm); - - mmu_notifier_invalidate_range_start(&range); unmap_single_vma(tlb, vma, start, end, NULL); - mmu_notifier_invalidate_range_end(&range); return 0; } @@ -855,7 +833,9 @@ static long madvise_dontneed_free(struct mmu_gather *tlb, int behavior) { struct mm_struct *mm = vma->vm_mm; + struct mmu_notifier_range range; unsigned long end = *pend; + long ret; *prev = vma; if (!can_madv_lru_vma(vma)) @@ -901,10 +881,20 @@ static long madvise_dontneed_free(struct mmu_gather *tlb, VM_WARN_ON(start >= end); } + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, start, + end); + + lru_add_drain(); + update_hiwater_rss(mm); + mmu_notifier_invalidate_range_start(&range); + if (behavior == MADV_DONTNEED) - return madvise_dontneed_single_vma(tlb, vma, start, end); + ret = madvise_dontneed_single_vma(tlb, vma, start, end); else /* behavior == MADV_FREE */ - return madvise_free_single_vma(tlb, vma, start, end); + ret = madvise_free_single_vma(tlb, vma, start, end); + + mmu_notifier_invalidate_range_end(&range); + return ret; } static long madvise_populate(struct vm_area_struct *vma,