Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: add missing VALGRIND_SET_CLEAN() to ringbuf libpmem2 example #5604

Conversation

ldorau
Copy link
Member

@ldorau ldorau commented Apr 25, 2023

Add missing VALGRIND_SET_CLEAN() to ringbuf libpmem2 example (found by pmemcheck).

Ref: #5598


This change is Reviewable

@ldorau ldorau force-pushed the exmaples-add-missing-perists-to-ringbuf-libpmem2-example branch from a013152 to 5449737 Compare April 25, 2023 10:51
@ldorau ldorau changed the title exmaples: add missing persists to ringbuf libpmem2 example examples: add missing persists to ringbuf libpmem2 example Apr 25, 2023
@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Merging #5604 (4262f88) into stable-1.13 (01eb891) will increase coverage by 1.57%.
The diff coverage is n/a.

❗ Current head 4262f88 differs from pull request most recent head 204229f. Consider uploading reports for the commit 204229f to get more accurate results

@@               Coverage Diff               @@
##           stable-1.13    #5604      +/-   ##
===============================================
+ Coverage        72.68%   74.25%   +1.57%     
===============================================
  Files              145      145              
  Lines            22634    22131     -503     
  Branches          3771     3705      -66     
===============================================
- Hits             16451    16433      -18     
+ Misses            6183     5698     -485     

@janekmi janekmi added this to the 1.13 on GHA milestone Apr 27, 2023
@ldorau ldorau force-pushed the exmaples-add-missing-perists-to-ringbuf-libpmem2-example branch from 5449737 to 153d82b Compare April 27, 2023 10:05
@ldorau ldorau changed the base branch from master to stable-1.13 April 27, 2023 10:07
@ldorau
Copy link
Member Author

ldorau commented Apr 27, 2023

Rebased to pmem:stable-1.13.

Copy link
Contributor

@grom72 grom72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ldorau)

Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ldorau)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

	ringbuf_data_force_page_allocation(rbuf->data, size);
	rbuf->persist(rbuf->data, sizeof(*rbuf->data));

As far as I can tell, the above is just a performance optimization, the persistent state remains intact.

It doesn't feel right to persist a block just to make Valgrind silent. I don't see any other argument for calling here persist. Am I missing something?

Do we have any recommended way of dealing with this kind of situation?

Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ldorau)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

	ringbuf_data_force_page_allocation(rbuf->data, size);
	rbuf->persist(rbuf->data, sizeof(*rbuf->data));

With the proposed fix I still got an issue:

Number of stores not made persistent: 2
Stores not made persistent properly:
[0]    at 0x401064: ringbuf_data_force_page_allocation (ringbuf.c:88)
   by 0x401308: ringbuf_new (ringbuf.c:167)
   by 0x401960: main (ringbuf.c:431)
	Address: 0x7cfe000	size: 1	state: DIRTY
[1]    at 0x401064: ringbuf_data_force_page_allocation (ringbuf.c:88)
   by 0x401308: ringbuf_new (ringbuf.c:167)
   by 0x401960: main (ringbuf.c:431)
	Address: 0x7cff000	size: 1	state: DIRTY
Total memory not made persistent: 2
ERROR SUMMARY: 2 errors

It looks like the following solves the issue definitely.

ringbuf_data_force_page_allocation(rbuf->data, size);
rbuf->persist(rbuf->data, size);

@ldorau ldorau force-pushed the exmaples-add-missing-perists-to-ringbuf-libpmem2-example branch from 153d82b to 4262f88 Compare May 4, 2023 12:40
@ldorau ldorau requested review from grom72 and janekmi May 4, 2023 12:41
Copy link
Member Author

@ldorau ldorau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @grom72 and @janekmi)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, janekmi (Jan Michalski) wrote…

With the proposed fix I still got an issue:

Number of stores not made persistent: 2
Stores not made persistent properly:
[0]    at 0x401064: ringbuf_data_force_page_allocation (ringbuf.c:88)
   by 0x401308: ringbuf_new (ringbuf.c:167)
   by 0x401960: main (ringbuf.c:431)
	Address: 0x7cfe000	size: 1	state: DIRTY
[1]    at 0x401064: ringbuf_data_force_page_allocation (ringbuf.c:88)
   by 0x401308: ringbuf_new (ringbuf.c:167)
   by 0x401960: main (ringbuf.c:431)
	Address: 0x7cff000	size: 1	state: DIRTY
Total memory not made persistent: 2
ERROR SUMMARY: 2 errors

It looks like the following solves the issue definitely.

ringbuf_data_force_page_allocation(rbuf->data, size);
rbuf->persist(rbuf->data, size);

Right. Done.

@ldorau ldorau requested a review from pbalcer May 4, 2023 14:02
Copy link
Member Author

@ldorau ldorau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @grom72, @janekmi, and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, janekmi (Jan Michalski) wrote…

As far as I can tell, the above is just a performance optimization, the persistent state remains intact.

It doesn't feel right to persist a block just to make Valgrind silent. I don't see any other argument for calling here persist. Am I missing something?

Do we have any recommended way of dealing with this kind of situation?

This persist is needed only to silent Valgrind, because the writes in ringbuf_data_force_page_allocation() are made only to ensure that all the pages for the ring buffer data are allocated (by rewriting a byte from each page), so they do not need to be persisted at all. I do not know how make Valgrind know that ...

@pbalcer Do you know how to make Valgrind not require to persist a store?

Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @grom72 and @pbalcer)

Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @grom72 and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, ldorau (Lukasz Dorau) wrote…

This persist is needed only to silent Valgrind, because the writes in ringbuf_data_force_page_allocation() are made only to ensure that all the pages for the ring buffer data are allocated (by rewriting a byte from each page), so they do not need to be persisted at all. I do not know how make Valgrind know that ...

@pbalcer Do you know how to make Valgrind not require to persist a store?

We are probably looking for VALGRIND_PMC_SET_CLEAN().

Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @grom72 and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, janekmi (Jan Michalski) wrote…

We are probably looking for VALGRIND_PMC_SET_CLEAN().

Or even VALGRIND_SET_CLEAN().

Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @grom72 and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, janekmi (Jan Michalski) wrote…

Or even VALGRIND_SET_CLEAN().

https://github.com/pmem/pmdk/blob/master/src/common/set.c#L149

🤣

Add missing VALGRIND_SET_CLEAN() to ringbuf libpmem2 example
(found by pmemcheck).

Ref: pmem#5598

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
@ldorau ldorau force-pushed the exmaples-add-missing-perists-to-ringbuf-libpmem2-example branch from 4262f88 to 204229f Compare May 4, 2023 14:55
Copy link
Member Author

@ldorau ldorau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @grom72 and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, janekmi (Jan Michalski) wrote…

https://github.com/pmem/pmdk/blob/master/src/common/set.c#L149

🤣

:-D Done.

@ldorau ldorau changed the title examples: add missing persists to ringbuf libpmem2 example examples: add missing VALGRIND_SET_CLEAN() to ringbuf libpmem2 example May 4, 2023
Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @grom72, @ldorau, and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 237 at r3 (raw file):

	if (rbuf->granularity == PMEM2_GRANULARITY_BYTE) {
		__atomic_store_n(pos, val, __ATOMIC_RELEASE);
		VALGRIND_SET_CLEAN(pos, sizeof(val));

Oh. Why do you think persist is not necessary here? 🤔

Copy link
Contributor

@janekmi janekmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @grom72, @ldorau, and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, ldorau (Lukasz Dorau) wrote…

:-D Done.

😆

Alright. I think this would be the most satisfying solution but it has not been done till now. And I reckon it might be tricky to do it right. So, I propose to proceed as follows:

ringbuf_data_force_page_allocation(rbuf->data, size);
// The persist below is unnecessary for the persistency correctness.
// It is needed only to work around Valgrind's pmemcheck limitation.
// XXX the following could be potentially replaced with VALGRIND_SET_CLEAN().
rbuf->persist(rbuf->data, sizeof(*rbuf->data));

src/examples/libpmem2/ringbuf/ringbuf.c line 237 at r3 (raw file):

Previously, janekmi (Jan Michalski) wrote…

Oh. Why do you think persist is not necessary here? 🤔

And here I am pretty sure a simple:

rbuf->persist(pos, sizeof(val));

is needed. As you have proposed initially.

ldorau added a commit to ldorau/pmdk that referenced this pull request May 5, 2023
ex_libpmem2/TEST6 would require two VALGRIND_SET_CLEAN() calls
to be added to the "src/examples/libpmem2/ringbuf/ringbuf.c"
example (see pmem#5604)
in order to pass under pmemcheck, but it seems that examples
do not use valgrind macros on purpose (to avoid unnecessary
complication), so this test just should not be run under pmemcheck.

Fixes: pmem#5598

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
@ldorau ldorau requested a review from janekmi May 5, 2023 08:49
Copy link
Member Author

@ldorau ldorau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @grom72, @janekmi, and @pbalcer)


src/examples/libpmem2/ringbuf/ringbuf.c line 168 at r1 (raw file):

Previously, janekmi (Jan Michalski) wrote…

😆

Alright. I think this would be the most satisfying solution but it has not been done till now. And I reckon it might be tricky to do it right. So, I propose to proceed as follows:

ringbuf_data_force_page_allocation(rbuf->data, size);
// The persist below is unnecessary for the persistency correctness.
// It is needed only to work around Valgrind's pmemcheck limitation.
// XXX the following could be potentially replaced with VALGRIND_SET_CLEAN().
rbuf->persist(rbuf->data, sizeof(*rbuf->data));

This persist is unnecessary, because ringbuf_data_force_page_allocation() performs 1 byte stores just to force allocation of pages and those stores do not need to be persisted. So the code is correct.

In order to be able to run this code under pmemcheck two VALGRIND_SET_CLEAN() calls would have to be added (as they are currently).
However, it seems that examples do not use any valgrind macros on purpose (to avoid unnecessary complication), so I believe this example just should not be run under pmemcheck and the correct fix is following: #5618 (and this pull request should be closed).


src/examples/libpmem2/ringbuf/ringbuf.c line 237 at r3 (raw file):

Previously, janekmi (Jan Michalski) wrote…

And here I am pretty sure a simple:

rbuf->persist(pos, sizeof(val));

is needed. As you have proposed initially.

It is explained above:

	 * However, if the map can be persistently written to with byte
	 * granularity (i.e., the system is eADR equipped), then data
	 * visibility is the same as data persistence. This eliminates the
	 * need for the persistent flag algorithm.

Code quote:

	 * However, if the map can be persistently written to with byte
	 * granularity (i.e., the system is eADR equipped), then data
	 * visibility is the same as data persistence. This eliminates the
	 * need for the persistent flag algorithm.
	 */

@ldorau ldorau marked this pull request as draft May 5, 2023 08:49
@ldorau
Copy link
Member Author

ldorau commented May 5, 2023

Replaced with #5618

@ldorau ldorau closed this May 5, 2023
ldorau added a commit to ldorau/pmdk that referenced this pull request May 5, 2023
ex_libpmem2/TEST6 would require two VALGRIND_SET_CLEAN() calls
to be added to the "src/examples/libpmem2/ringbuf/ringbuf.c"
example (see pmem#5604)
in order to pass under pmemcheck, but it seems that examples
do not use valgrind macros on purpose (to avoid unnecessary
complication), so this test just should not be run under pmemcheck.

Fixes: pmem#5598

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
@ldorau ldorau deleted the exmaples-add-missing-perists-to-ringbuf-libpmem2-example branch May 5, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants