Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5588417pxb; Mon, 28 Mar 2022 14:37:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0P3MdYT9lbxBpYPqkyYDA+ex9jXZrH0DBTKqAgNzmjoIZLIyFDnJwgljkWUr4eDGDePlj X-Received: by 2002:a67:ed1a:0:b0:325:ad13:6219 with SMTP id l26-20020a67ed1a000000b00325ad136219mr4581893vsp.13.1648503449094; Mon, 28 Mar 2022 14:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648503449; cv=none; d=google.com; s=arc-20160816; b=aSCv6WdtbsqeoxoMT8jhRnZ/cBxl60phzKVAP2g3+o9TmBTae54FGTzFtMXOQi/UXL eFLKR6ujigutKQR24kkAWQY1fsroFj7qxuNQP5vgfcMqBfESoovca4N+kUkY9kMCf5TY j0/XGh/QhDwEbeFS6axNnyGcgRmVlD8rcQXzZMtiCmObxD+pdiExEsvBFZ2SLqrDGq0v ohdxMfXAdnQRvvX7a9uVritvHfI7HFCgC7ybuvkpj3nxaQRWsADU8hc4wxvVg8u7NAS+ CYFAAvk9mf1b8WAlAQN0kXMg8tQD0l2lQTPGGyt4sCS+OMcLMZBr8Dxx1sTPH54r7UFM vscg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fPHcThhavYQoi1CRvCTyZV8TYj/0992Wtfs4sW93D/I=; b=jVZjPuOAq7M6NCZyhz6AY4p59g/fGJn+uvHPz6oYF9ozEwsHL+EScXncdinM68bpsG kt7Fvrmgr2j6+ixVAv93H2kxxsn4s5l7zyMCQFrRVShF7UC8ijx2gZZUTJXsx2RstYn+ +iNzUJpzY8rw0wrncz1dvfNYdRsTjc/jEMUvJEqEGYK40IUy2s02JlrMqXXqzA6mRXJk O01Ge5fPbrjL6fugy7jXtnur33DNBo5d3KHN9fQtWuwjrUi37zbvjoGLrKPxzudR8R9/ wnc0MQN2C/SkixQKzUFwgm/6rce3zV7oSURp0bQG+MfTh4o0UKlaly29pZ8AYZK1eoP3 As0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Ndlw/8Us"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v207-20020a672fd8000000b00324c5c3bf60si2690569vsv.418.2022.03.28.14.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:37:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Ndlw/8Us"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 81EDE7628D; Mon, 28 Mar 2022 14:15:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245531AbiC1TPj (ORCPT + 99 others); Mon, 28 Mar 2022 15:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234522AbiC1TPi (ORCPT ); Mon, 28 Mar 2022 15:15:38 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6376483A8 for ; Mon, 28 Mar 2022 12:13:56 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id p10so20585333lfa.12 for ; Mon, 28 Mar 2022 12:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fPHcThhavYQoi1CRvCTyZV8TYj/0992Wtfs4sW93D/I=; b=Ndlw/8Us34OEJZq/npk2kS+igmzvUQCNI/fg/kB0v2fEuXBXD2WikwIN4dTzk2MNqu 9TJWkML/0Xv7P8la/hH3Mn7LYbKA9mMzyt6kgbUQBELx8ZyjdHH8IsnNAdScOe1Hxw+E cXoTsKmvvOY1MZ5izparRhp5siMFuJ87zMo45G4hBxF6MIs3bbeOXbkNw6qi02/I5hzf Aud6rjbOuNpdq/SvyDaYW4T/0lIGeuaaGETpTl3k/4p5x6kvk++bfbgfFPIIkBlT20kJ DsUltenM6gEZ58KIVZcn8lFBlXba9ulIvOWSqCs1hMQXlsXAWn/0j0j4zMD0I4kb8nf2 wn7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fPHcThhavYQoi1CRvCTyZV8TYj/0992Wtfs4sW93D/I=; b=NdA22iMZXrtE3EWmpwrg6RjMngnPpRzT3jV2DNhhHbnVhU2XY4uoHN07evrri6yGJ1 RyvHXicr+dejMmuu81l+ZpgeojJPY/OmEKD802H4ZV63XNVuqB9yB//BLOcYP8HKW+F5 7Icpr0YorQV0VToiZkdkotWQezjDQLKFdIRB7jxUNyx878mDhCoQ+GA+LwV0xTfwcP4M Ws7Aj25L+b43gRtTSmIlyY+blvKpRO6r4Z639N6V/TTpf0hm92XeGAE3EiDBBEdz767/ szqjTi1Mgm+XMURTwbY4cCrt9cgNAfkFEYqp3z0Ot8jDWO1xD+O3n92jW1wzGI+uu4XT aSdw== X-Gm-Message-State: AOAM532mnA/T41rgY6s9/cl3XkQyEhDJM2pM2TFoeCAjF8SRc/+qHgU2 ekMn7fNF6LsYSAXFyGwVmJ8tl+YTYW+1HgcMc76SLw== X-Received: by 2002:ac2:5d49:0:b0:44a:37de:9d98 with SMTP id w9-20020ac25d49000000b0044a37de9d98mr21134273lfd.580.1648494834715; Mon, 28 Mar 2022 12:13:54 -0700 (PDT) MIME-Version: 1.0 References: <20220325233125.413634-1-vipinsh@google.com> In-Reply-To: From: Vipin Sharma Date: Mon, 28 Mar 2022 12:13:18 -0700 Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: Speed up slot_rmap_walk_next for sparsely populated rmaps To: Paolo Bonzini Cc: David Matlack , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm list , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thank you David and Paolo, for checking this patch carefully. With hindsight, I should have explicitly mentioned adding "noinline" in my patch email. On Sun, Mar 27, 2022 at 3:41 AM Paolo Bonzini wrote: > > On 3/26/22 01:31, Vipin Sharma wrote: > >>> -static void slot_rmap_walk_next(struct slot_rmap_walk_iterator *iterator) > >>> +static noinline void > >> > >> What is the reason to add noinline? > > > > My understanding is that since this method is called from > > __always_inline methods, noinline will avoid gcc inlining the > > slot_rmap_walk_next in those functions and generate smaller code. > > > > Iterators are written in such a way that it's way more beneficial to > inline them. After inlining, compilers replace the aggregates (in this > case, struct slot_rmap_walk_iterator) with one variable per field and > that in turn enables a lot of optimizations, so the iterators should > actually be always_inline if anything. > > For the same reason I'd guess the effect on the generated code should be > small (next time please include the output of "size mmu.o"), but should > still be there. I'll do a quick check of the generated code and apply > the patch. Yeah, I should have added the "size mmu.o" output. Here is what I have found: size arch/x86/kvm/mmu/mmu.o Without noinline: text data bss dec hex filename 89938 15793 72 105803 19d4b arch/x86/kvm/mmu/mmu.o With noinline: text data bss dec hex filename 90058 15793 72 105923 19dc3 arch/x86/kvm/mmu/mmu.o With noinline, increase in size = 120 Curiously, I also checked file size with "ls -l" command File size: Without noinline: 1394272 bytes With noinline: 1381216 bytes With noinline, decrease in size = 13056 bytes I also disassembled mmu.o via "objdump -d" and found following Total lines in the generated assembly: Without noinline: 23438 With noinline: 23393 With noinline, decrease in assembly code = 45 I can see in assembly code that there are multiple "call" operations in the "with noinline" object file, which is expected and has less lines of code compared to "without noinline". I am not sure why the size command is showing an increase in text segment for "with noinline" and what to infer with all of this data. Thanks Vipin