From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6253C433E2 for ; Tue, 15 Sep 2020 18:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8160D20936 for ; Tue, 15 Sep 2020 18:06:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="znz6kYk2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727431AbgIOSGo (ORCPT ); Tue, 15 Sep 2020 14:06:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727965AbgIOSDx (ORCPT ); Tue, 15 Sep 2020 14:03:53 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E74C061788 for ; Tue, 15 Sep 2020 11:03:52 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id v196so2427015pfc.1 for ; Tue, 15 Sep 2020 11:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nhPPje+UUTBY8kYUEvCGJHYilZbBe703Z6BQl0hi82o=; b=znz6kYk2M1HfniaapdTD5ndtoDBHFcJW8m8WFdFuJRD4CHnMx3DVnNgZbGlkGcfQyY /4/c6GGgxz1i1ALrxb0wjC/itd3L9/KDfk32rpsOmyXzHIf75v2j8TpIGouU0IfRo0A4 hNrCHJ1HpCS84uJ8dU70fbB0EthZ+75cxB3hrWAgn2YAiDkXlwel6axWVgtX+SH0iVzV IiTWNsM7oRf3tuTa3LzvDQNw4zskrFBDebDPRIme32GBauJ3YzgwqMTKmEAngzw6nxtU plv5nAAPRqeytkF/yTH5+YyooJJ2tzFWevNGTmDPPZq/scJ0B7wyCnHC+ZI+OUqMHVp9 olBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nhPPje+UUTBY8kYUEvCGJHYilZbBe703Z6BQl0hi82o=; b=lsfsrUaDq7R/v+J1l5VshcXHgY81zZphLmPZy4B21awuKg8zOzgA25rEA0aD8ySTc8 mpu16JVx0Q8oce7hEyZJdVkWs81EE5N6XgKb+5wv6mThHXJuSAfPPvOIK1yJ0nN82J/M lOOi/fQsKDuA8Q2sjRl3wKIQUasdSOXip+Z7OzougFrEZr6UrQqxB1V9Vt6iIGrE1Zbv is6BhE/U65k6okwLn1o4kTUELNm0Yi2Z6zwDYHIeDBnVimfojOSOq73/bRNrNrenHnS0 k4oDQSyplF8FdRDCEFGoZAuZMLk8dAAnGYNtxhqvr7PZDZMADFH8TimxWWPRAAT2rTCH 3N1A== X-Gm-Message-State: AOAM531J2kkKQ11dKesQXEAdQr+MgSFn6X4J6JheFYjHKRy0hAjvJQaz fhTL6EBS1NsuncuoFJZHaH1uYpJEixyiO+bERcggMQ== X-Google-Smtp-Source: ABdhPJxm8mfbd1RkNg+nNZEp7K1x8W811B13DkAefYfGlQ8VvBcsuWI2MpSoCr5ODfRzGBd9GbAXzfHNNbAMFtRvCl4= X-Received: by 2002:a62:e40c:0:b029:13f:d777:f70e with SMTP id r12-20020a62e40c0000b029013fd777f70emr12683616pfh.2.1600193031738; Tue, 15 Sep 2020 11:03:51 -0700 (PDT) MIME-Version: 1.0 References: <20200915125947.26204-1-songmuchun@bytedance.com> <20200915143241.GH5449@casper.infradead.org> <20200915154213.GI5449@casper.infradead.org> <20200915173948.GK5449@casper.infradead.org> In-Reply-To: <20200915173948.GK5449@casper.infradead.org> From: Muchun Song Date: Wed, 16 Sep 2020 02:03:15 +0800 Message-ID: Subject: Re: [External] Re: [RFC PATCH 00/24] mm/hugetlb: Free some vmemmap pages of hugetlb page To: Matthew Wilcox Cc: Jonathan Corbet , Mike Kravetz , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, David Rientjes , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 16, 2020 at 1:39 AM Matthew Wilcox wrote: > > On Wed, Sep 16, 2020 at 01:32:46AM +0800, Muchun Song wrote: > > On Tue, Sep 15, 2020 at 11:42 PM Matthew Wilcox wrote: > > > > > > On Tue, Sep 15, 2020 at 11:28:01PM +0800, Muchun Song wrote: > > > > On Tue, Sep 15, 2020 at 10:32 PM Matthew Wilcox wrote: > > > > > > > > > > On Tue, Sep 15, 2020 at 08:59:23PM +0800, Muchun Song wrote: > > > > > > This patch series will free some vmemmap pages(struct page structures) > > > > > > associated with each hugetlbpage when preallocated to save memory. > > > > > > > > > > It would be lovely to be able to do this. Unfortunately, it's completely > > > > > impossible right now. Consider, for example, get_user_pages() called > > > > > on the fifth page of a hugetlb page. > > > > > > > > Can you elaborate on the problem? Thanks so much. > > > > > > OK, let's say you want to do a 2kB I/O to offset 0x5000 of a 2MB page > > > on a 4kB base page system. Today, that results in a bio_vec containing > > > {head+5, 0, 0x800}. Then we call page_to_phys() on that (head+5) struct > > > page to get the physical address of the I/O, and we turn it into a struct > > > scatterlist, which similarly has a reference to the page (head+5). > > > > As I know, in this case, the get_user_pages() will get a reference > > to the head page (head+0) before returning such that the hugetlb > > page can not be freed. Although get_user_pages() returns the > > page (head+5) and the scatterlist has a reference to the page > > (head+5), this patch series can handle this situation. I can not > > figure out where the problem is. What I missed? Thanks. > > You freed pages 4-511 from the vmemmap so they could be used for > something else. Page 5 isn't there any more. So if you return head+5, > then when we complete the I/O, we'll look for the compound_head() of > head+5 and we won't find head. > We do not free pages 4-511 from the vmemmap. Actually, we only free pages 128-511 from the vmemmap. The 512 struct pages occupy 8 pages of physical memory. We only free 6 physical page frames to the buddy. But we will create a new mapping just like below. The virtual address of the freed pages will remap to the second page frame. So the second page frame is reused. When a hugetlbpage is preallocated, we can change the mapping to bellow. hugetlbpage struct page(8 pages) page frame(8 pages) +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | | 1 | -------------> | 1 | | | | 2 | -------------> +-----------+ | | | 3 | -----------------^ ^ ^ ^ ^ | | | 4 | -------------------+ | | | | 2M | | 5 | ---------------------+ | | | | | 6 | -----------------------+ | | | | 7 | -------------------------+ | | +-----------+ | | | | +-----------+ As you can see, we reuse the first tail page. -- Yours, Muchun From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A05EC43461 for ; Tue, 15 Sep 2020 18:03:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C6EA02193E for ; Tue, 15 Sep 2020 18:03:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="znz6kYk2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6EA02193E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 36A94900076; Tue, 15 Sep 2020 14:03:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31B60900057; Tue, 15 Sep 2020 14:03:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2332D900076; Tue, 15 Sep 2020 14:03:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 0A740900057 for ; Tue, 15 Sep 2020 14:03:54 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C0084181AEF09 for ; Tue, 15 Sep 2020 18:03:53 +0000 (UTC) X-FDA: 77266069146.13.lunch56_5c085ca27113 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 8D53318140B72 for ; Tue, 15 Sep 2020 18:03:53 +0000 (UTC) X-HE-Tag: lunch56_5c085ca27113 X-Filterd-Recvd-Size: 7057 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 18:03:52 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id j34so2387234pgi.7 for ; Tue, 15 Sep 2020 11:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nhPPje+UUTBY8kYUEvCGJHYilZbBe703Z6BQl0hi82o=; b=znz6kYk2M1HfniaapdTD5ndtoDBHFcJW8m8WFdFuJRD4CHnMx3DVnNgZbGlkGcfQyY /4/c6GGgxz1i1ALrxb0wjC/itd3L9/KDfk32rpsOmyXzHIf75v2j8TpIGouU0IfRo0A4 hNrCHJ1HpCS84uJ8dU70fbB0EthZ+75cxB3hrWAgn2YAiDkXlwel6axWVgtX+SH0iVzV IiTWNsM7oRf3tuTa3LzvDQNw4zskrFBDebDPRIme32GBauJ3YzgwqMTKmEAngzw6nxtU plv5nAAPRqeytkF/yTH5+YyooJJ2tzFWevNGTmDPPZq/scJ0B7wyCnHC+ZI+OUqMHVp9 olBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nhPPje+UUTBY8kYUEvCGJHYilZbBe703Z6BQl0hi82o=; b=JrgSfAgYmYHf/Wtl9bz22hGhXgztyiwfnAA1qJ40d0Su1KmzG+U0OPt1hCwS53oGTd dPRhulBCHuNE1+iaJJXywyyVdpPOhvqGbXplBzKY+cCgCs6pJYJIAC9BJXmOL840p3WP gWTZnw/zzajbuOXYTKyHGuf3vH7fqibVUHaHGDHdWdkoKtlsZHr5qzY62di0QjrBmyh0 N68Y02MCaLa1HoH4yFQ7vdfoIySYG9JW7l7eSfaDaS2CPCDD0xQOv2sUJMB6N/lGvt4j mJtPVZoGMA61NGkAqn5igzJp6AJdo7pZXtCI1XQVSYBQSB6A5aZi3ifzFoH+n9iQ8Mlb 3QEQ== X-Gm-Message-State: AOAM530/ttuktH5rQkuK00ttHzn3bMg3tLt1MFBIsxrUojtphckBfB/c fvWoLul7iCM1o1ri9ySd2Si0M4SwiF36fIWCtsMbtA== X-Google-Smtp-Source: ABdhPJxm8mfbd1RkNg+nNZEp7K1x8W811B13DkAefYfGlQ8VvBcsuWI2MpSoCr5ODfRzGBd9GbAXzfHNNbAMFtRvCl4= X-Received: by 2002:a62:e40c:0:b029:13f:d777:f70e with SMTP id r12-20020a62e40c0000b029013fd777f70emr12683616pfh.2.1600193031738; Tue, 15 Sep 2020 11:03:51 -0700 (PDT) MIME-Version: 1.0 References: <20200915125947.26204-1-songmuchun@bytedance.com> <20200915143241.GH5449@casper.infradead.org> <20200915154213.GI5449@casper.infradead.org> <20200915173948.GK5449@casper.infradead.org> In-Reply-To: <20200915173948.GK5449@casper.infradead.org> From: Muchun Song Date: Wed, 16 Sep 2020 02:03:15 +0800 Message-ID: Subject: Re: [External] Re: [RFC PATCH 00/24] mm/hugetlb: Free some vmemmap pages of hugetlb page To: Matthew Wilcox Cc: Jonathan Corbet , Mike Kravetz , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, David Rientjes , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 8D53318140B72 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: On Wed, Sep 16, 2020 at 1:39 AM Matthew Wilcox wrote: > > On Wed, Sep 16, 2020 at 01:32:46AM +0800, Muchun Song wrote: > > On Tue, Sep 15, 2020 at 11:42 PM Matthew Wilcox wrote: > > > > > > On Tue, Sep 15, 2020 at 11:28:01PM +0800, Muchun Song wrote: > > > > On Tue, Sep 15, 2020 at 10:32 PM Matthew Wilcox wrote: > > > > > > > > > > On Tue, Sep 15, 2020 at 08:59:23PM +0800, Muchun Song wrote: > > > > > > This patch series will free some vmemmap pages(struct page structures) > > > > > > associated with each hugetlbpage when preallocated to save memory. > > > > > > > > > > It would be lovely to be able to do this. Unfortunately, it's completely > > > > > impossible right now. Consider, for example, get_user_pages() called > > > > > on the fifth page of a hugetlb page. > > > > > > > > Can you elaborate on the problem? Thanks so much. > > > > > > OK, let's say you want to do a 2kB I/O to offset 0x5000 of a 2MB page > > > on a 4kB base page system. Today, that results in a bio_vec containing > > > {head+5, 0, 0x800}. Then we call page_to_phys() on that (head+5) struct > > > page to get the physical address of the I/O, and we turn it into a struct > > > scatterlist, which similarly has a reference to the page (head+5). > > > > As I know, in this case, the get_user_pages() will get a reference > > to the head page (head+0) before returning such that the hugetlb > > page can not be freed. Although get_user_pages() returns the > > page (head+5) and the scatterlist has a reference to the page > > (head+5), this patch series can handle this situation. I can not > > figure out where the problem is. What I missed? Thanks. > > You freed pages 4-511 from the vmemmap so they could be used for > something else. Page 5 isn't there any more. So if you return head+5, > then when we complete the I/O, we'll look for the compound_head() of > head+5 and we won't find head. > We do not free pages 4-511 from the vmemmap. Actually, we only free pages 128-511 from the vmemmap. The 512 struct pages occupy 8 pages of physical memory. We only free 6 physical page frames to the buddy. But we will create a new mapping just like below. The virtual address of the freed pages will remap to the second page frame. So the second page frame is reused. When a hugetlbpage is preallocated, we can change the mapping to bellow. hugetlbpage struct page(8 pages) page frame(8 pages) +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | | 1 | -------------> | 1 | | | | 2 | -------------> +-----------+ | | | 3 | -----------------^ ^ ^ ^ ^ | | | 4 | -------------------+ | | | | 2M | | 5 | ---------------------+ | | | | | 6 | -----------------------+ | | | | 7 | -------------------------+ | | +-----------+ | | | | +-----------+ As you can see, we reuse the first tail page. -- Yours, Muchun