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=-5.2 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 5084AC48BE8 for ; Wed, 16 Jun 2021 07:59:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFE7B613EF for ; Wed, 16 Jun 2021 07:59:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFE7B613EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5294E6B0070; Wed, 16 Jun 2021 03:59:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D8FC6B0071; Wed, 16 Jun 2021 03:59:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 304E26B0072; Wed, 16 Jun 2021 03:59:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id EE4616B0070 for ; Wed, 16 Jun 2021 03:59:33 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 80628180AD806 for ; Wed, 16 Jun 2021 07:59:33 +0000 (UTC) X-FDA: 78258837426.33.7C76693 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id D78629001460 for ; Wed, 16 Jun 2021 07:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623830372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ydQaNNt01ob73exPiqxRV+4741Z1kAkyQHRaIWVUuy4=; b=CRGKW/Inh3vV5l1dYeNtIiDeceMif8MJnw9k72tSz5JNywO4asCwA8RazlunZAaYVmyojl 7b6lrJGU15qi83YfdZfxq3IPySMWfUpAMa9kWGHkD+IkRP8uwixaQBwF/m32O77+ruW4ge SVmKvkW4Ao4Le/+nxpRdVQazn2UZETg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-132-NtAdkLcSPFKV0gT-CdpRQg-1; Wed, 16 Jun 2021 03:59:29 -0400 X-MC-Unique: NtAdkLcSPFKV0gT-CdpRQg-1 Received: by mail-wr1-f72.google.com with SMTP id l13-20020adfe9cd0000b0290119a0645c8fso726019wrn.8 for ; Wed, 16 Jun 2021 00:59:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=ydQaNNt01ob73exPiqxRV+4741Z1kAkyQHRaIWVUuy4=; b=ZYbZawQ6nuzFDEpnMz93J3fGFrCpXndgBPCh3vVFiuvlL0ymYB/jg+t8b26jjvEYY8 I/3O1Y/zeE7axe20e42CITkiMuOJplgjLZGPnhPxThrJ270Lmt1LasZk564OzyCT67uI Dl05k0wNUK9cgMZUXqnbXcdzBxJ/aORd13rRkFBzSENlnI0xkQr30O4F0XJhi7PJK05t mQvt/gHvqv6QI/wS6czh/MLz548bjO3rpqY/L4u8sVAafcEWbARipqSrBAkdVrhVJWjf g7Mz5QMdC/89LRyL1BqLfpm+3CUmXbYssJ88o0WJ5gGWFHFAgscCnd2ZKFGzY/2DgKtF q75A== X-Gm-Message-State: AOAM533dDpbhu0ji3mhrKVHlU6tC9ZgO/+wbY+CQJiZRF8eEiGBYNzBY RxU8GAUYl1qbO/iK1RFlH8wE450y67GE2/hJx1hNRSVgF5wWTSmeQUpzvd98NWFzvmk/4vP6QQS PEbfBvaLqyIA= X-Received: by 2002:a5d:4cd1:: with SMTP id c17mr3730013wrt.295.1623830367960; Wed, 16 Jun 2021 00:59:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI+HmoKMAJWCUeDjNq1GKPkINAc/59yB1cZZb2CSDdwCyPD1ZeNIHMH4RgrhqWcABWv5jBMA== X-Received: by 2002:a5d:4cd1:: with SMTP id c17mr3729984wrt.295.1623830367701; Wed, 16 Jun 2021 00:59:27 -0700 (PDT) Received: from [192.168.3.132] (p5b0c6524.dip0.t-ipconnect.de. [91.12.101.36]) by smtp.gmail.com with ESMTPSA id q20sm1564928wrf.45.2021.06.16.00.59.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Jun 2021 00:59:27 -0700 (PDT) Subject: Re: [RFC PATCH] mm/page_reporting: Adjust threshold according to MAX_ORDER To: Gavin Shan , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com, Anshuman Khandual , Alexander Duyck References: <20210601033319.100737-1-gshan@redhat.com> <76516781-6a70-f2b0-f3e3-da999c84350f@redhat.com> <0c0eb8c8-463d-d6f1-3cec-bbc0af0a229c@redhat.com> <74b0d35f-707d-aa11-19e7-fedb74d77159@redhat.com> From: David Hildenbrand Organization: Red Hat Message-ID: <6ebc99f9-649d-fbd2-aadf-87291e41b36d@redhat.com> Date: Wed, 16 Jun 2021 09:59:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <74b0d35f-707d-aa11-19e7-fedb74d77159@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="CRGKW/In"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf19.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: 783fir3ourwj9azprkmf4ekac7sjfknn X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D78629001460 X-HE-Tag: 1623830360-71116 Content-Transfer-Encoding: quoted-printable 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 16.06.21 03:53, Gavin Shan wrote: > On 6/14/21 9:03 PM, David Hildenbrand wrote: >> On 11.06.21 09:44, Gavin Shan wrote: >>> On 6/1/21 6:01 PM, David Hildenbrand wrote: >>>> On 01.06.21 05:33, Gavin Shan wrote: >>>>> The PAGE_REPORTING_MIN_ORDER is equal to @pageblock_order, taken as >>>>> minimal order (threshold) to trigger page reporting. The page repor= ting >>>>> is never triggered with the following configurations and settings o= n >>>>> aarch64. In the particular scenario, the page reporting won't be tr= iggered >>>>> until the largest (2 ^ (MAX_ORDER-1)) free area is achieved from th= e >>>>> page freeing. The condition is very hard, or even impossible to be = met. >>>>> >>>>> =C2=A0=C2=A0=C2=A0 CONFIG_ARM64_PAGE_SHIFT:=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 16 >>>>> =C2=A0=C2=A0=C2=A0 CONFIG_HUGETLB_PAGE:=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= Y >>>>> =C2=A0=C2=A0=C2=A0 CONFIG_HUGETLB_PAGE_SIZE_VARIABLE:=C2=A0=C2=A0=C2= =A0 N >>>>> =C2=A0=C2=A0=C2=A0 pageblock_order:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 13 >>>>> =C2=A0=C2=A0=C2=A0 CONFIG_FORCE_MAX_ZONEORDER:=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 14 >>>>> =C2=A0=C2=A0=C2=A0 MAX_ORDER:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 14 >>>>> >>>>> The issue can be reproduced in VM, running kernel with above config= urations >>>>> and settings. The 'memhog' is used inside the VM to access 512MB an= onymous >>>>> area. The QEMU's RSS doesn't drop accordingly after 'memhog' exits. >>>>> >>>>> =C2=A0=C2=A0=C2=A0 /home/gavin/sandbox/qemu.main/build/qemu-system= -aarch64=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >>>>> =C2=A0=C2=A0=C2=A0 -accel kvm -machine virt,gic-version=3Dhost=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >>>>> =C2=A0=C2=A0=C2=A0 -cpu host -smp 8,sockets=3D2,cores=3D4,threads=3D= 1 -m 4096M,maxmem=3D64G \ >>>>> =C2=A0=C2=A0=C2=A0 -object memory-backend-ram,id=3Dmem0,size=3D204= 8M=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >>>>> =C2=A0=C2=A0=C2=A0 -object memory-backend-ram,id=3Dmem1,size=3D204= 8M=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >>>>> =C2=A0=C2=A0=C2=A0 -numa node,nodeid=3D0,cpus=3D0-3,memdev=3Dmem0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >>>>> =C2=A0=C2=A0=C2=A0 -numa node,nodeid=3D1,cpus=3D4-7,memdev=3Dmem1=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 :=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >>>>> =C2=A0=C2=A0=C2=A0 -device virtio-balloon-pci,id=3Dballoon0,free-p= age-reporting=3Dyes >>>>> >>>>> This tries to fix the issue by adjusting the threshold to the small= er value >>>>> of @pageblock_order and (MAX_ORDER/2). With this applied, the QEMU'= s RSS >>>>> drops after 'memhog' exits. >>>> >>>> IIRC, we use pageblock_order to >>>> >>>> a) Reduce the free page reporting overhead. Reporting on small chunk= s can make us report constantly with little system activity. >>>> >>>> b) Avoid splitting THP in the hypervisor, avoiding downgraded VM per= formance. >>>> >>>> c) Avoid affecting creation of pageblock_order pages while hinting i= s active. I think there are cases where "temporary pulling sub-pageblock = pages" can negatively affect creation of pageblock_order pages. Concurren= t compaction would be one of these cases. >>>> >>>> The monstrosity called aarch64 64k is really special in that sense, = because a) does not apply because pageblocks are just very big, b) does s= ometimes not apply because either our VM isn't backed by (rare) 512MB THP= or uses 4k with 2MB THP and c) similarly doesn't apply in smallish VMs b= ecause we don't really happen to create 512MB THP either way. >>>> >>>> >>>> For example, going on x86-64 from reporting 2MB to something like 32= KB is absolutely undesired. >>>> >>>> I think if we want to go down that path (and I am not 100% sure yet = if we want to), we really want to treat only the special case in a specia= l way. Note that even when doing it only for aarch64 with 64k, you will s= till end up splitting THP in a hypervisor if it uses 64k base pages (b)) = and can affect creation of THP, for example, when compacting (c), so ther= e is a negative side to that. >>>> >>> >>> [Remove Alexander from the cc list as his mail isn't reachable] >>> >> >> [adding his gmail address which should be the right one] >> >>> David, thanks for your time to review and sorry for the delay and lat= e response. >>> I spent some time to get myself familiar with the code, but there are= still some >>> questions to me, explained as below. >>> >>> Yes, @pageblock_order is currently taken as page reporting threshold.= It will >>> incur more overhead if the threshold is decreased as you said in (a). >> >> Right. Alex did quite some performance/overhead evaluation when introd= ucing this feature. Changing the reporting granularity on most setups (es= p., x86-64) is not desired IMHO. >> >=20 > Thanks for adding Alex's correct mail address, David. >=20 >>> >>> This patch tries to decrease the free page reporting threshold. The @= pageblock_order >>> isn't touched. I don't understand how the code changes affecting THP = splitting >>> and the creation of page blocks mentioned in (b) and (c). David, coul= d you please >>> provide more details? >> >> Think of it like this: while reporting to the hypervisor, we temporari= ly turn free/"movable" pieces part of a pageblock "unmovable" -- see __is= olate_free_page()->del_page_from_free_list(). While reporting them to the= hypervisor, these pages are not available and not even marked as PageBud= dy() anymore. >> >> There are at least two scenarios where this could affect creation of f= ree pageblocks I can see: >> >> a. Compaction. While compacting, we might identify completely movable/= free pageblocks, however, actual compaction on that pageblock can fail be= cause some part is temporarily unmovable. >> >> b. Free/alloc sequences. Assume a pageblocks is mostly free, except tw= o pages (x and y). Assume the following sequence: >> >> 1. free(x) >> 2. free(y) >> 3. alloc >> >> Before your change, after 1. and 2. we'll have a free pageblock. 3 won= 't allocate from that pageblock. >> >> With your change, free page reporting might run after 1. After 2, we'l= l not have a free pageblock (until free page reporting finished), and 3. = might just reallocate what we freed in 2 and prevent having a free pagebl= ock. >> >> >> No idea how relevant both points are in practice, however, the fundame= ntal difference to current handling is that we would turn parts of pagebl= ocks temporarily unmovable, instead of complete pageblocks. >> >=20 > Thank you for the details. Without my changes and the page reporting th= reshold > is @pageblock_order, the whole page block can become 'movable' from 'un= movable'. > I don't think it's what we want, but I need Alex's confirm. __isolate_free_page() will set the pageblock MIGRATE_MOVABLE in that=20 case. It's only temporarily unmovable, while we're hinting. Note that MOVABLE vs. UNMOVABLE is just grouping for free pages, and=20 even setting it to the wrong migratetype isn't "wrong" as in=20 "correctness". It doesn't make a difference if there are no free pages=20 because the whole block is isolated. --=20 Thanks, David / dhildenb