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=-8.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 42EA5C433E0 for ; Wed, 8 Jul 2020 21:18:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1831D206E2 for ; Wed, 8 Jul 2020 21:18:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="FaEi03fj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbgGHVSC (ORCPT ); Wed, 8 Jul 2020 17:18:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbgGHVSC (ORCPT ); Wed, 8 Jul 2020 17:18:02 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BC68C061A0B for ; Wed, 8 Jul 2020 14:18:02 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id gc9so116169pjb.2 for ; Wed, 08 Jul 2020 14:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=vv68x9SyvRhGqitYXr8FYZE9kVtAZHNXCyl5tRHN7qI=; b=FaEi03fjp9juvK+9ymnJbo0OG0XKaRx5OY1uQW73ga2dKn1DxGfru+Obvjc+ALfCSw dsYL40JebOfHWma0q74zDEbIy9hhhVO4bCTVld0ZXxjR2a+meaMpEGzW6BY/nXpVP6Gs 0vUBPZ83zqRBb+25emHcUL4a+zr2CbVPc6AFPNabJb3P4ahGdiLv2fUAne2L5FksLiUs T0eZt542c10hCqPAAm6M8RLKmyVDBGonvc3uYi1u4xClD3/4qfaIugJQB1oXTLHsUh+A iZTQQhGrzMw/kDgdn2LGmKBYwzb197j+6zxYv6n/Uf9YAxfQE6bFUSI3M84plnvVsaTx SYwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=vv68x9SyvRhGqitYXr8FYZE9kVtAZHNXCyl5tRHN7qI=; b=i9uvaRqKVOwQ71/E3TDBgarihZbpTyC94dIFaL5ZpY8cd57vlRSWypxPq2YKxAezD+ HotRqBsX/t0xp6n9IXcTJHUMRsv7Sh4LANDj8LMGOiVptpTPPaO2EuBLyl6mbtKNvbBi 6dl/HuIqMjImP4Uuw2bjJ20rwMPH/cxC+U2xNqDxTZwqGt/GHjX76nqJZ03C8o5xE1D/ eXGjwrUyE9/MXlb8CZRwY4B0AtC9aIdHxJAE1XcKxx1FLpmHF6vXnnLjSBeV3EtrYhTH ObTq/+IsurgKKR62kxTIzBybeICBsqCJ+9tVt/g34FLUDlpKiX9TZf5hF9PB+pmCEx0N mejQ== X-Gm-Message-State: AOAM531QKB/LqjGrN5K/iTeFS0j2HD/zRPOjHHmsSeXpOJxUYU24yVt0 7i0nLGmWAD6on1F90sAwtnrwngwFMBgcZA== X-Google-Smtp-Source: ABdhPJys/s/u+O4YEFG+S95UCHQThy8wp1Xwm6avDLH6nVOf1l1aTgrpjy6joQw8Zr3zPDqrbKoUFw== X-Received: by 2002:a17:90a:7487:: with SMTP id p7mr11554894pjk.233.1594243081736; Wed, 08 Jul 2020 14:18:01 -0700 (PDT) Received: from [192.168.1.182] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id a9sm637760pfr.103.2020.07.08.14.18.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jul 2020 14:18:01 -0700 (PDT) To: io-uring From: Jens Axboe Subject: [PATCH] io_uring: only call kfree() for a non-zero pointer Message-ID: Date: Wed, 8 Jul 2020 15:18:00 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org It's safe to call kfree() with a NULL pointer, but it's also pointless. Most of the time we don't have any data to free, and at millions of requests per second, the redundant function call adds noticeable overhead (about 1.3% of the runtime). Signed-off-by: Jens Axboe --- Kinda silly, this is 100% reproducible. Actually somewhat baffled that kfree() isn't a inline, to avoid a function call if the pointer is NULL. diff --git a/fs/io_uring.c b/fs/io_uring.c index 14168fbc7d79..51ff88330f9a 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1519,7 +1519,8 @@ static void io_dismantle_req(struct io_kiocb *req) if (req->flags & REQ_F_NEED_CLEANUP) io_cleanup_req(req); - kfree(req->io); + if (req->io) + kfree(req->io); if (req->file) io_put_file(req, req->file, (req->flags & REQ_F_FIXED_FILE)); __io_put_req_task(req); -- Jens Axboe