Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2417304rdh; Sun, 26 Nov 2023 05:58:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEL5yN9FXqV8ZI0rxbC9QdSYzFV3B9LHccwXmkReSDbYJ/+O9hW36LzZdykFOLqo2yXrt+4 X-Received: by 2002:a05:6808:42:b0:3b8:3442:8d99 with SMTP id v2-20020a056808004200b003b834428d99mr9325113oic.20.1701007100642; Sun, 26 Nov 2023 05:58:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701007100; cv=none; d=google.com; s=arc-20160816; b=JPHfsoNPmNfa7jpBKm9PC/DdgFX0jD8JxLBsELl8l4TFULIcPafSsbmacI7E39QL2v 6umDNL4rCWz68PsV6trzSenaV+jua1UrPINMpV8WMVKZC6T8Fqieh3LG4LaDp7zNNc0u L5Tvb4V6CAlmKH7wOSjKK/iM+gmTR7Ibc8YrzCBp7tgi2frKXO9elqjDdNlbwlFcb6jP 4/Q55IuV5tCfnI3okKA8PbkRZzB2BH4IKrIzRnPcg1Y3qgHZb7+R/F0z5lJ2hs/Sleqh JvTSo+6csDhJuTdnvFEnE1mRrhpDXTIdQGZ4JIXxwd/xYHfq6LsJm04pdeAWf/BWw1EZ MDZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9VJ0rA3r7NTPoB0XFwR/Lf+pF2vP6kSME4kg3g2wpTc=; fh=GUcLtHMS/ptH6z2qMV4TCGpaBA7HqdT6RGYI0U+TxnU=; b=qA048Emm6BzO1RpW0ymM9iPjBzyickMALRL6KUyRAriEuZvn1BA03zIRUCzizorJcH AOYDd9e5xt1YkBp8RmIekR1mkT3A5BEkdYb9e4PZ7hISTrG+bw/RUr0cgSHNcAJWzPzB OG+cDBdCuJ48STCk/Tb+/DhGrO+kmaaIWgw/yrZ3xI6mD/Pp5jU9hq7jRGqxhsDpB/JZ gKyixZIQSeRnOmeeqjM/2nf2aiY7FunzKmisqbjEuTWvL82Wz6+MdoiTsQfXdOsSsUjL 814MhTMtpu5dEqcr+yj2y32rQhtdgTjbDxOkVDD//hmDTw8vWC/Kyc8ghMc/CiUGMUcv rNzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lw5y9c1r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id p1-20020a634f41000000b005b95ee3edc6si7766351pgl.628.2023.11.26.05.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 05:58:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lw5y9c1r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 61A4F809988A; Sun, 26 Nov 2023 05:58:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbjKZNr2 (ORCPT + 99 others); Sun, 26 Nov 2023 08:47:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjKZNr1 (ORCPT ); Sun, 26 Nov 2023 08:47:27 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13355D9 for ; Sun, 26 Nov 2023 05:47:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=9VJ0rA3r7NTPoB0XFwR/Lf+pF2vP6kSME4kg3g2wpTc=; b=lw5y9c1ry4n30Bn0J1WuMtPLdN 11Ow8mx7FVsIXslY6+Nje0sBgLNOFldGpOB6Z9G5TRknB/CtaLXS1LU1r7manFVX+4vCPi8NNhSaX JDWN8mtj+9HUMAlxf26MaBxJdfEVQKSjF4D8qiVXs8Z8QyDXLl4zPxqJ/26h9+I0UCGS7pz45jWqZ Kh7ZjCJL1o9lv7J3cUd59b+AXTSjccl/RnpdTcdLcTm325dohDfiXQk/xOiEIKi2PsgQoTkxXK4+W 4d//hEHj7WkAGJp4LsWkaw/2P+tJjyMhUFZtdd26GBeivCCd7d6vDpGoQAogwLAHhs/KdAiwApk3M iUj1iTYw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1r7FTi-00AYix-IB; Sun, 26 Nov 2023 13:47:18 +0000 Date: Sun, 26 Nov 2023 13:47:18 +0000 From: Matthew Wilcox To: David Wang <00107082@163.com> Cc: liam.howlett@oracle.com, akpm@linux-foundation.org, ankitag@nvidia.com, bagasdotme@gmail.com, chunn@nvidia.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, regressions@lists.linux.dev, surenb@google.com Subject: Re: [REGRESSION]: mmap performance regression starting with k-6.1 Message-ID: References: <20231123143452.erzar3sqhg37hjxz@revolver> <20231126071854.19490-1-00107082@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231126071854.19490-1-00107082@163.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 26 Nov 2023 05:58:12 -0800 (PST) On Sun, Nov 26, 2023 at 03:18:54PM +0800, David Wang wrote: > I add memory access between mmap and munmap to the simple stress, and timeit. It's still not a very good benchmark ... > My test code now is: > > #define MAXN 1024 > struct { void* addr; size_t n; } maps[MAXN]; > void accessit(char *addr, size_t n) { > for (int i=0; i } > int main() { > int i, n, k, r; > void *p; > for (i=0; i n = 1024*((rand()%32)+1); > p = mmap(NULL, n, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); So 'n' is now a number between 1kB and 32kB. That's not terribly realistic; I'd say you want to be more like n = 4096 * ((rand() % 512) + 1)); > for (i=0; i<10000000; i++) { > k = rand()%MAXN; > #ifdef PAGE_FAULT > accessit((char*)maps[k].addr, maps[k].n); > #endif > r = munmap(maps[k].addr, maps[k].n); > if (r) { > perror("fail to munmap"); > return -1; > } > n = 1024*((rand()%32)+1); > p = mmap(NULL, n, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); Are you simulating something a real application actually does? Because this all seems very weird and micro-benchmark to me. The real applications we've benchmarked see a speedup so I'm not thrilled about chasing down something that no real application does. In terms of what's going on in the kernel, for each loop, you're calling munmap(), taking between 1 and 8 page faults, then calling mmap(). That may just be too few page faults to see the benefit of the maple tree.