From patchwork Mon Nov 18 02:18:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13878032 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 03354D10F40 for ; Mon, 18 Nov 2024 02:21:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68F506B00BA; Sun, 17 Nov 2024 21:21:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6164C6B00BB; Sun, 17 Nov 2024 21:21:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B84B6B00BC; Sun, 17 Nov 2024 21:21:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 26D556B00BA for ; Sun, 17 Nov 2024 21:21:44 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9F26C4011E for ; Mon, 18 Nov 2024 02:21:43 +0000 (UTC) X-FDA: 82797613416.23.6D33040 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by imf21.hostedemail.com (Postfix) with ESMTP id 09CF21C0007 for ; Mon, 18 Nov 2024 02:20:09 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="THKB/B7U"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731896320; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=iBAl2pVHqSjJxyZYZ+jfmp0PGB7vomHGb+9H8zMxgbQ=; b=JgnI9AS+Mb/7nVy/Z3p2u9ZCgbuoq7T4CUWGYdCajwv9O/oiIgZqxmNuUY/4EvficLdNde aoF3N/RDb0BxHR5F+apc3xe6ySqSx2jKE5dlVHVLloKNF1hg/Mtumgjim/lcpdDHMWEhGc EXSuhZFtdQqjXWhSF7oairv25T5P3RM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="THKB/B7U"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731896320; a=rsa-sha256; cv=none; b=TbSeHJNCZ81UvpX0Hg66tnfMjol+fOobQIBacHIxSCDOWI7cibwADUtWkPqA31P6wzJhPp K9yf/4PLsYeBitf59zAbzJZgAGWE8Nq/5Mi+b98aS2HMkPwohMv/1FiNK/lw6WbrBM7pQc 5hTa2qAo/zTzrzj2AZ5r76T+ZEpp6LQ= Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a99eb8b607aso494542966b.2 for ; Sun, 17 Nov 2024 18:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731896500; x=1732501300; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iBAl2pVHqSjJxyZYZ+jfmp0PGB7vomHGb+9H8zMxgbQ=; b=THKB/B7UNAHyzVXoZcMnMT4uyrWygI3VxlwwkI/ur4DJY7l1EgEOw/FDrAf9pb0c2/ aASNZsFaa32didJliqiQ7RCzO6fNm1RHDQY3fyvnTMlrXQcFy2zFtD2HwL2NFOMJfhUY NZbb6HRM0GXvQ0uEfiTtvEU33F26SYhlZ2b3icCo9yHIhcgheyp4Hl/UC5AyxAfUtpYt Xi1+YWJaJP5xlFsqEtAWPopSzGtYbErkSB6HmshGuFM6noxph/+1Scs2NWLWP4gEXHY4 /yIuDPf0BUrXjdwhU/BO8iTU5625n+Qlym0v/J2t4BlAmf6zw7PYBk6HAkqnB8SgwyyC RFtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731896500; x=1732501300; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iBAl2pVHqSjJxyZYZ+jfmp0PGB7vomHGb+9H8zMxgbQ=; b=b18Cmn+w+EPD+CIwhQIHaR8no9mlgkToR3X4aUf7GrmCrywCZbUlUchSWF9azRBpZM zyv9caOGLt0vk4DweyIqDbwsC2FgtDxhGE+UH99uw4sCjb8K3nSaMvwhLvSI7sl9iQfg tjkkeVWRdW5DZmIKAnmgEf18d5aYcpm0xIJ19FBkbdtToptCEPFlspiGe3VjXlHJz6MR FB2ux4dncM8tjj52RjrBPn/eQGVPajSVmb+H+A0HLwlBCv0lQWdBTN8/TLNKwpbJlE0D VPyDBznPT88JnQM4qsdXSrMBWtGH7QYLOCC134P1EztxFTU8BbX8j/1V/2qDtDCZwMh4 /NOg== X-Gm-Message-State: AOJu0YzrFLv7tohmMKQJ2uJ3p4+S38nvrUrMIPX+L9flXhSJw20s9Tcc 3+4blJCUdqpg0UYMrrSbOanGn1cX6ns0+rBZTR7h6r0M3U9atn4D X-Google-Smtp-Source: AGHT+IGZyP/IC5jVSBejH0cFlhumOFmRBkiiSoSEZgmVsvSPWXhJfZDh5xMw9xazkJXREspJmWZTDQ== X-Received: by 2002:a17:907:2cc7:b0:a99:529d:81ae with SMTP id a640c23a62f3a-aa48355272bmr932114566b.55.1731896500240; Sun, 17 Nov 2024 18:21:40 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e044bb8sm479270266b.150.2024.11.17.18.21.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Nov 2024 18:21:38 -0800 (PST) From: Wei Yang To: akpm@linux-foundation.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com Cc: linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" Subject: [PATCH] mm/vma: check retry_merge only for new vma case Date: Mon, 18 Nov 2024 02:18:23 +0000 Message-Id: <20241118021823.17386-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 09CF21C0007 X-Stat-Signature: zm9adoymfje7bq5p587i8z33jsqpbqsx X-Rspam-User: X-HE-Tag: 1731896409-994116 X-HE-Meta: U2FsdGVkX185VHR6SNgXHVHRHlcsnx7zzwnvnNpKLoFhc2i0efxVb6dH+EeBGK0ouMCbFsJUn4M2WO/o6q+xsQ3knDAQo1uQ5VFmVrm37rrjaraK3zS0gfNfSdTIcFM9vHjQMFtag+0nUB8LyHkiT2+F4he3F+SfJbPZVJ9BGVdY5iVoDqJUFbPZ7DEhzaNLnuiUasQWEcJhXOmN7PelB3IyshCMx3ONCYa4tG2lAPxQQVUkvmwWUpX+qP6dpSjz3yc2yTD5jKWXrIdoe4yxc3Bx3eGWzzjHaufavpNF0iIBmAVn2a03QYjQQznGWhFaVNSYB59gFvlXbBVLnz6ZU0C5ElsAW4wMFMWCxQKspSDVuLtEHV1eVAs+8w2ShjHlNsjk+atdXfscz0zqL4VW1JYvOxxuS1veScMIDuBPxI9ZCih3naLMj78nWu1VZfSNrVAh2JxurzNwuN8HHlG+p91taOZZBolHRc+Bg5RnmH7OFdM0J/su9e0obqlKhQHWNAh3nezyM9hVaop7EpPi0Z+ANzKbehTo2z5+SXkfLWTFyf5g1y9Ro5Qg1a+fMEp4z01X1C+fNC9CjAAjn3F5HsnIctFnu/ecnJvSqYMXWkHK2N+dQWenrqjJrAoWru8/rtWYcJsnDPmgdF3nhqIEji6KosDd3/xkA6QsfPOTjVWiC68yOGO/8F+gad49Tp0hOOMgLue5aXkJ+hnsQzbu0iEbu+If0FMMMHeh4dvBZWUTVZg7vkCRGTwhmF1sqe+4BzBBCVWr7vvFJzVlCqwor++BDFW6KIo3PEJHMNZONTs880ZsA/nNN+zZwrdkKt2qRB2Zp2SGU+4sHYbjYo7pZVPf96/r8jkJXWG/sCRciS4hiom8nCZQgAjTgbmGB0VerHjgRoEgTNg6ixn5+Oc+7ncGBp0lsWCulR5v50HIEYkxK9IWJk3qCvOsLkLPXDflc0AQhJzSXytZOR8ofKp BzVs+b5s 9gEa9as+2EvWa7S7YrkECnHVgUkOcgkoNeOrvOva66hbZ1lYlvpYLsuYtxb5NCEnvbJF3sb7AHchi8YA6G0w/yhSDdBwMVL7UkK6O6R79jPyKpoZf9LZ/uI4az+frRy465qiJkCK3Ov26Doa2ky+Y31LTysGKNKlVGIxhNbstTFqOXEyMEEGSfa4SyNviKyoBuM403hOBHXPaotP+boglLryfEqQjTlsMX9+SGZH3b6xseRa3mUW7XYFBeeMmSBURWWR+ajAeR71SXjmzL13W59e4AiiDw/khUBSrnZoy4J3fcVP7NZzMDNexCR7nROJzn+CNG/0xcMEJLyarLjt4sPOmpaLdPzv9FTbQDejtpnGz7IyZS8ZG42NQ8+RjRA/p8pSohQsQaDOdpp2ddEhmN9Pb7yRK4iTCd0e/NYwb8U6vBfxQzYsXKUqdgRMxQRGLEH/48ss05BRWESXN1Yb0z1YX1pGVmSzV6xau6r1tSKuNpbAFQEtlCTFCmdee7GnXL4pWzgjCkLJ7Yqs+y0ty8/+rQg== 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: List-Subscribe: List-Unsubscribe: Current code logic looks like this: __mmap_region() vma = vma_merge_new_range(&vmg) if (!vma) __mmap_new_vma(&map, &vma) __mmap_new_file_vma(map, vma) map->retry_merge = xxx --- (1) if (map.retry_merge) vma_merge_existing_range(vmg, &map, vma) Location (1) is the only place where map.retry_merge is set, this means it is not necessary to check it if already merged with adjacent vma. Let's move the check and following operation into new vma case. Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Lorenzo Stoakes CC: Vlastimil Babka CC: Jann Horn --- mm/vma.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 8a454a7bbc80..80b1bd404f23 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -2456,14 +2456,14 @@ unsigned long __mmap_region(struct file *file, unsigned long addr, error = __mmap_new_vma(&map, &vma); if (error) goto unacct_error; - } - /* If flags changed, we might be able to merge, so try again. */ - if (map.retry_merge) { - VMG_MMAP_STATE(vmg, &map, vma); + /* If flags changed, we might be able to merge, so try again. */ + if (map.retry_merge) { + VMG_MMAP_STATE(vmg, &map, vma); - vma_iter_config(map.vmi, map.addr, map.end); - vma_merge_existing_range(&vmg); + vma_iter_config(map.vmi, map.addr, map.end); + vma_merge_existing_range(&vmg); + } } __mmap_complete(&map, vma);