From nobody Fri Jun 23 19:00:36 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Qnmm33qLtz4gk6q for ; Fri, 23 Jun 2023 19:00:51 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Qnmm242yGz48Bh for ; Fri, 23 Jun 2023 19:00:50 +0000 (UTC) (envelope-from asomers@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.221.175 as permitted sender) smtp.mailfrom=asomers@gmail.com; dmarc=none Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-45739737afcso316706e0c.2 for ; Fri, 23 Jun 2023 12:00:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687546849; x=1690138849; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GVmq+Z7aIB5np7voqeLhBHujXZjh3gpAShSyL5Xxvm8=; b=Osf7MtO3CgItGlHslQrF+wl+6zLwizjKLfwP3i5F3QygwDH+cwPsi8SoqfNkmoX02c OSw7b5W0+HYjXgNrF4ZoO8W8GPBiMVHUb1a9BAEhH6gxhuaYGSckNelvYecrJy2Qy9ha 5BQLnCeKdrJgk2MUhmmIQ2rm59cwHk9n5B2cWKZygo3NNUooq+pqlPOjg9lcx8Yj/FBt ZefvZiBqR/OKWNP6bFzxDtbRnfREGviKKsMUg20wPztPvctHwH7J+OVVqsiouXrlqbs6 gN98AJCRQ7b5/o8+oTv6ge50+H7ie08G+72bz8WvvIwRklsHu1/LiqvmAH6hRcMELmPg rFXA== X-Gm-Message-State: AC+VfDwFpi1PLZCUQsAQk3UP318T8e16KjBG5Po0E458XgbNdoLw+qxf A58vl+v/9YlFIUZ2RxMRRmwQ8pD8twftKpsb1/vtOBojFyW4gw== X-Google-Smtp-Source: ACHHUZ6SbE52rX73+fAje8enjKNPHghpWiQDGTIbooX38dbRsPKmwnOhw9Ij6fG02DfjnGepOqApfa+BXfTn0hvUohk= X-Received: by 2002:a1f:e643:0:b0:474:3a0d:3dee with SMTP id d64-20020a1fe643000000b004743a0d3deemr6289197vkh.5.1687546848720; Fri, 23 Jun 2023 12:00:48 -0700 (PDT) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 From: Alan Somers Date: Fri, 23 Jun 2023 12:00:36 -0700 Message-ID: Subject: Should close() release locks atomically? To: FreeBSD Hackers Content-Type: text/plain; charset="UTF-8" X-Spamd-Result: default: False [-1.79 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; NEURAL_HAM_SHORT(-0.99)[-0.990]; NEURAL_HAM_LONG(-0.81)[-0.805]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; RCVD_IN_DNSWL_NONE(0.00)[209.85.221.175:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; FROM_HAS_DN(0.00)[]; TO_DOM_EQ_FROM_DOM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.221.175:from]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; TO_DN_ALL(0.00)[]; FREEFALL_USER(0.00)[asomers]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com]; ARC_NA(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Queue-Id: 4Qnmm242yGz48Bh X-Spamd-Bar: - X-ThisMailContainsUnwantedMimeParts: N The close() syscall automatically releases locks. Should it do so atomically or is a delay permitted? I can't find anything in our man pages or the open group specification that says. The distinction matters when using O_NONBLOCK. For example: fd = open(..., O_DIRECT | O_EXLOCK | O_NONBLOCK); //succeeds // do some I/O close(fd); fd = open(..., O_DIRECT | O_EXLOCK | O_NONBLOCK); //fails with EAGAIN! I see this error frequently on a heavily loaded system. It isn't a typical thread race though; ktrace shows that only one thread tries to open the file in question. From the ktrace, I can see that the final open() comes immediately after the close(), with no intervening syscalls from that thread. It seems that close() doesn't release the lock right away. I wouldn't notice if I weren't using O_NONBLOCK. Should this be considered a bug? If so I could try to come up with a minimal test case. But it's somewhat academic, since I plan to refactor the code in a way that will eliminate the duplicate open(). -Alan